Skip to content

Instantly share code, notes, and snippets.

  • Save j4jeyaram/a9167e981d91e682f58613ba83a24d86 to your computer and use it in GitHub Desktop.
Save j4jeyaram/a9167e981d91e682f58613ba83a24d86 to your computer and use it in GitHub Desktop.
Write a program which repeatedly reads numbers until the user enters “done”. Once “done” is entered, print out the total, count, and average of the numbers. If the user enters anything other than a number, detect their mistake using try and except and print an error message and skip to the next number.
count=0
total = 0
inp = 1
while True:
try:
number = input('Enter a number')
if number == 'done':
break
inp = int(number)
count = count + 1
total = total + inp
#continue
except:
print('Enter a valid number')
print(count, total/count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment