Last active
May 30, 2020 23:34
-
-
Save jmangrad/8c06e2d1742a29e70b4a0141eb6780df to your computer and use it in GitHub Desktop.
Exercise-3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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