Question
Python get floats(): This function will take a single integer argument which is the number of floats to be obtained from the user. It will
Python
get floats(): This function will take a single integer argument which is the number of floats to be obtained from the user. It will create an empty list, use a for-loop to prompt and obtain floats from the user, append each float to the list it created, and return the list.
Dene a function called summer() that sums the elements in a list of numbers. It takes a single list argument. First you need to initialize an accumulator to zero, then use a for-loop to add the value of each element in the list, and nally return the total sum to the calling program.
average(): the function average() takes the list of numbers returned by get floats() as its argument and returns the average value, a oat, to the calling program. average() uses summer() to sum the values in the list. Its body can actually be a single line: a return statement with the appropriate expression following the keyword return.
std dev() : The function std dev() takes two arguments, the list of numbers obtained by get floats and the average obtained using average(), and returns the standard deviation, a float value. Your function should initialize an accumulator to zero and then use a for-loop in which the average is subtracted from the list value and the result is squared and added to the accumulator. After the for loop has nished, the accumulator should be divided by the number of elements in the list, the square root taken, and the result returned to the calling function. main(): This function will take no arguments. It will prompt the user for the number of floats s/he wants to enter, and it will call get floats() with the integer value entered by the user, call function average() which takes no arguments and calls std dev() to obtain the standard deviation and then prints the result. Hints: Dont forget to convert your input as appropriate. A simple one-argument range() function can be used as the iterable in the for-loop header.
Enter the number of list elements: 5
Enter float 1: 30
Enter float 2: 40
Enter float 3: 50
Enter float 4: 60
Enter float 5: 70
Average = 50.0
Standard deviation = 14.1421356237
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started