Create a function called avgSumOf Squares that expects no arguments. Instead, th
ID: 3667548 • Letter: C
Question
Create a function called avgSumOf Squares that expects no arguments. Instead, this function gets its input from the user at the keyboard. The function asks the user to enter a series of numbers, one at a time. The user types end to indicate that there are no more numbers. The function computes the average of the sum of the squares of all the values entered. For example, given the values 6, -3, 4, 2, 11, 1, and -9, the sum of the squares would be (36 + 9+ 16 + 4+ 121 + 1 + 81) = 268. The average of the sum of squares would then be 268/7 = 38.285714285714285. The function then prints the average of the sum of the squares and returns that average. However, if end is entered before any values are entered, the function notifies the user that no numbers were entered and returns None. You may assume the user inputs are valid: they will either be a number or the string end. Here are some examples of how your function should behave:Explanation / Answer
def avgSumOfSquares():
a = []
total = 0.0
while 1:
i = raw_input("Enter next number: ") #if raw_input is not working then try input("Enter next number: ")
if i=="end":
break;
else:
a.append(float(i))
if(a!=[]):
for i in a:
total += i*i
average = total*1.0/len(a)
print "The average of the sum of squares is " + str(average)
else:
print "No numbers were entered"
avgSumOfSquares()
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.