Answer to Question #333677 in Python for mani

Question #333677

In this exercise you will create a program that computes the average of a collection of values entered by the user. The user will enter 0 as a sentinel value to indicate that no further values will be provided. Your program should display an appropriate error message if the first value entered by the user is 0.


1
Expert's answer
2022-04-25T15:15:30-0400
print("Input some integers to calculate their sum and average. Input 0 to exit.")
count = 0
sum = 0
number = 1

while number != 0:
  number = int(input())
  sum = sum + number
  count += 1

if count == 1:
  print("Input some numbers")
else:
  average = sum / (count - 1)
  average = float('{:.3f}'.format(average))
  print("Average of the above numbers are: ", average)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS