-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoops and iterations.py
39 lines (28 loc) · 1.05 KB
/
Loops and iterations.py
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
# 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.
# Setting Largest and Smallest to none
Largest = None
Smallest = None
# creating a loop that will iterate through the user inputted values
while True:
number = input ("Enter an integer: ")
# code to end the loop
if number == "done":
break
try:
inumber = int (number)
snumber = int (number)
except :
print ("enter valid integer")
if Smallest is None :
Smallest = snumber
elif snumber < Smallest:
Smallest = snumber
if Largest is None:
Largest = inumber
elif inumber > Largest:
Largest = inumber
print ("Smallest = " + str (Smallest) )
print ("Largest is : " + str (Largest))