-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassignment_5_2.py
More file actions
24 lines (22 loc) · 831 Bytes
/
assignment_5_2.py
File metadata and controls
24 lines (22 loc) · 831 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
'''
# 5.2 Write a program that repeatedly prompts a user for integer numbers until the user enters 'done'.
Once 'done' is entered, print out the largest and smallest of the numbers.
If the user enters anything other than a valid number catch it with a try/except and put out an appropriate message and ignore the number.
Enter the numbers from the book for problem 5.1 and Match the desired output as shown.
'''
largest = None
smallest = None
while True:
num = raw_input("Enter a number: ")
if num == "done" : break
try:
num = int(num)
if largest is None or num > largest:
largest = num
if smallest is None or num < smallest:
smallest = num
except:
print "Invalid input"
continue
print "Maximum is ", largest
print "Minimum is ", smallest