-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeek7_Assignment_5_1.py
More file actions
35 lines (30 loc) · 812 Bytes
/
Week7_Assignment_5_1.py
File metadata and controls
35 lines (30 loc) · 812 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
28
29
30
31
32
33
34
35
'''Write a program that repeatedly prompts a user for integer numbers until the user enters done.
Once done, print out the largest and smallest of the numbers.
If the user enters anything other than a valid integer number,
catch it with try/except & put an appropriate message & ignoe the number.'''
largest = None
smallest = None
a = []
while True:
num = input("Enter a number: ")
try:
inum = int(num)
except:
msg = 'Invalid input'
if num == "done":
break
else:
a.append(inum)
for i in a:
if largest is None:
largest = i
elif i > largest:
largest = i
for j in a:
if smallest is None:
smallest = j
elif j < smallest:
smallest = j
print(msg)
print('Maximum is',largest)
print('Minimum is',smallest)