Skip to content

Commit f4ad697

Browse files
authored
Create Week7_Assignment_5_1.py
1 parent a7ec984 commit f4ad697

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

Week7_Assignment_5_1.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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)

0 commit comments

Comments
 (0)