PYTHON   21

average py

Guest on 23rd August 2022 11:02:29 AM

  1. total = 0
  2. count = 0
  3. while (True):
  4.     inp = input('Enter a number: ')
  5.     if inp == 'done':
  6.         break
  7.     try:
  8.         value = float(inp)
  9.     except:
  10.         print('Invalid input')
  11.         continue
  12.     total = total + value
  13.     count = count + 1
  14.  
  15. average = total / count
  16. print('Average:', average)

Raw Paste


Login or Register to edit or fork this paste. It's free.