Skip to content

Instantly share code, notes, and snippets.

@jmangrad
Last active May 30, 2020 23:34
Show Gist options
  • Save jmangrad/8c06e2d1742a29e70b4a0141eb6780df to your computer and use it in GitHub Desktop.
Save jmangrad/8c06e2d1742a29e70b4a0141eb6780df to your computer and use it in GitHub Desktop.
Exercise-3
Exercise 1: 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.
total = 0
count = 0
average = 0
while True:
try:
number = input("Enter a number: ")
if number == "done":
break
number = int(number)
count +=1
total =number + total
average = total / count
except:
print("Invalid input")
print("Total number of values you entered are: {}".format(count))
print("You're total values are: {}".format(total))
print("You're average values are: {}".format(average))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment