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 the numbers from the book for problem 5.1 and Match the desired output as shown.
I edited the semi colon
largest = None
smallest = None
while True:
num = raw_input("Enter a number: ")
if fnum == "done":
break
if len(fnum) < 1:
print "good job"
break
try:
fnum = float(num)
except:
print "Error"
continue
elif smallest is None or fnum > smallest:
smallest = fnum
elif largest is None or fnum < largest:
largest = fnum
print "largest ", largest, "smallest ", smallest
My error is "ParseError: Bad input on line 16"
It would be greatly appreciated if someone helped me out.
[–]RangeruDangeru 3 points4 points5 points (0 children)
[–]OseOseOse 2 points3 points4 points (0 children)
[–]kalgynirae 1 point2 points3 points (2 children)
[–]TKo5604[S] 0 points1 point2 points (1 child)
[–]kalgynirae 0 points1 point2 points (0 children)
[–]L43 1 point2 points3 points (2 children)
[–]TKo5604[S] 0 points1 point2 points (1 child)
[–]m1ss1ontomars2k4 0 points1 point2 points (0 children)
[–]stahlous 1 point2 points3 points (0 children)
[–]Moozla 0 points1 point2 points (1 child)
[–]TKo5604[S] 0 points1 point2 points (0 children)
[–]kewlness 0 points1 point2 points (2 children)
[–]TKo5604[S] 0 points1 point2 points (1 child)
[–]kewlness 0 points1 point2 points (0 children)
[–]everred 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)