-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex-5-1.py
More file actions
27 lines (21 loc) · 753 Bytes
/
ex-5-1.py
File metadata and controls
27 lines (21 loc) · 753 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 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.
isRunning = True
total = 0
count = 0
average = 0
while isRunning:
inputVal = input('Enter a number: ');
try:
inputValFloat = float(inputVal)
except Exception as e:
if inputVal.lower() == 'done':
break
else:
print('not a valid number')
total = total + inputValFloat
count = count + 1
print('Total: ', total)
print('Count: ', count)
print('Avg: ', total / count)