-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathch05ex2.py
30 lines (27 loc) · 865 Bytes
/
ch05ex2.py
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
28
29
30
# Exercise 1 for 5.1
# use try and except for non-number values
# now print out max and min numbers
count = 0
total = 0
maxvalue = None
minvalue = None
inputvalue = input("Enter a value: ")
while True:
try:
if inputvalue == "done":
break
else:
total = total + int(inputvalue)
count = count + 1
if maxvalue is None:
maxvalue = int(inputvalue)
minvalue = int(inputvalue)
elif maxvalue < int(inputvalue):
maxvalue = int(inputvalue)
elif minvalue > int(inputvalue):
minvalue = int(inputvalue)
inputvalue = input("Enter a value: ")
except:
print("Invalid input")
inputvalue = input("Enter a value: ")
print("Total",total, "Count",count,"MinValue", minvalue,"MaxValue", maxvalue)