-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassignment5_2.py
More file actions
50 lines (42 loc) · 1.38 KB
/
assignment5_2.py
File metadata and controls
50 lines (42 loc) · 1.38 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""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 7, 2, bob, 10, and 4 and match the output below."""
"""largest = None
smallest = None
while True:
x = input("Enter a number: ")
if x == "done" : break
try:
num = int(x)
except:
print("Invalid input")
continue
if smallest is None:
smallest = num
if (num) > (largest) :
largest = num
elif (num) < (smallest) :
smallest = num
print("Maximum is", int(largest))
print("Minimum is", int(smallest))
"""
largest = None
smallest = None
while True:
num = input("Enter a number: ")
if num == "done":
break
try:
#print (num)
num = int(num)
if largest is None or largest < num :
largest = num
elif smallest is None or smallest > num :
smallest = num
except:
print("Invalid input")
print ("Maximum is", largest)
print ("Minimum is", smallest)
#https://www.coursera.org/account/accomplishments/verify/X4KPFSUV5V8X?utm_source=link&utm_campaign=copybutton_certificate