The function of this program is repeatedly prompting a user for integer numbers until the user enters 'done'
. Once 'done'
is entered, print out the largest and smallest of the numbers. Suppose all input is proper, so we do not need to check whether the input value is illegal or not.
largest = None
smallest = None
while True :
num = raw_input("Enter a number: ")
if num == "done" :
break
try :
num = int(num)
except :
print "Invalid input"
continue
if largest is None :
largest = num
elif largest < num :
largest = num
if smallest is None :
smallest = num
elif num < smallest :
smallest = num
print "Maximum is", largest
print "Minimum is", smallest