File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ '''Write a program that repeatedly prompts a user for integer numbers until the user enters done.
2+ Once done, print out the largest and smallest of the numbers.
3+ If the user enters anything other than a valid integer number,
4+ catch it with try/except & put an appropriate message & ignoe the number.'''
5+
6+ largest = None
7+ smallest = None
8+
9+ a = []
10+
11+ while True :
12+ num = input ("Enter a number: " )
13+ try :
14+ inum = int (num )
15+ except :
16+ msg = 'Invalid input'
17+ if num == "done" :
18+ break
19+ else :
20+ a .append (inum )
21+
22+ for i in a :
23+ if largest is None :
24+ largest = i
25+ elif i > largest :
26+ largest = i
27+
28+ for j in a :
29+ if smallest is None :
30+ smallest = j
31+ elif j < smallest :
32+ smallest = j
33+ print (msg )
34+ print ('Maximum is' ,largest )
35+ print ('Minimum is' ,smallest )
You can’t perform that action at this time.
0 commit comments