Write a program that repeatedly takes integers from the user as long as he wants to input.
Answers
Explanation:
largest = None
smallest = None
while True:
try:
num = raw_input("Enter a number: ")
if num == 'done':
break;
n = int(num)
largest = num if largest < num or largest == None else largest
smallest = num if smallest > num or smallest == None else smallest
except:
print "Invalid input"
print "Maximum number is ", largest
print "Minimum number is ", smallest
Answer:
largest = None
smallest = None
while True:
try:
num = raw_input("Enter a number: ")
if num == "done":
break
#print (num)
num = int(num)
if largest is None or largest < num:
largest = num
elif smallest is None or smallest > num:
smallest = num
except ValueError:
print("Invalid input")
print ("Maximum is", largest)
print ("Minimum is", smallest)
#Enter 7,2,bob,10,4 u will get desired output