


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



Files to submit: hw4.py Functions to include in hw4.py:
**1. average()
Remember how to computer an average of a set of numbers: Average = Sum of numbers / Count of numbers What is a sentinel value: In computer programming, a sentinel value (also referred to as a flag value or signal value) is a special value that is used to terminate a loop that processes structured (especially sequential) data. The value should be selected in such a way that it will not be confused with legal data values. A programmer may choose any sentinel value, but here are some typical examples:
(blank) xxx FALSE END
Write a function that keeps asking the user for numbers until they enter -999. Print out the final average of all of the numbers. Use floats for all numbers! You may not assume that the user will enter a valid number before entering -999. If the user enters -999 as the first input, the function should print : No average could be computed. (Or something similar) instead of trying to divide by zero. You will need to use a while loop to accomplish this. Do NOT use recursion. Here is a simple algorithm you can use:
average() Enter the next number to average (type -999 to quit): 10. Enter the next number to average (type -999 to quit): 20. Enter the next number to average (type -999 to quit): 30. Enter the next number to average (type -999 to quit): - Average: 20. average() Enter the next number to average (type -999 to quit): 0 Enter the next number to average (type -999 to quit): - Average: 0. average() Enter the next number to average (type -999 to quit): 53. Enter the next number to average (type -999 to quit): 474. Enter the next number to average (type -999 to quit): - Enter the next number to average (type -999 to quit): 747 Enter the next number to average (type -999 to quit): 983. Enter the next number to average (type -999 to quit): 100. Enter the next number to average (type -999 to quit): - Average: 376.
pascal(7) 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 1 6 15 20 15 6 1 1 7 21 35 35 21 7 1 For Extra Credit: Make your pascal() function print out the triangle in the more traditional, symmetric form. For example: pascal(3) 1 1 1 1 2 1 1 3 3 1 pascal(6) 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 1 6 15 20 15 6 1
Be sure to name your file and functions exactly as indicated. READ THROUGH THE INSTRUCTIONS CAREFULLY. If you need help, be sure to come to office hours. Good Luck! Written by Aaron Hansen, Spring 2007