largest = none smallest = none while true: num = raw_input("enter number: ") if num == "done" : break if num>largest: largest=num if smallest none: smallest=num elif num<smallest: smallest=num try : n=float(num) except: print "invalid input" continue print num print "maximum", largest print "manimum", smallest
combining question text , comments, assume wonder why program output erroneous input largest
. answer should move try
block checking input right before update of largest
, smallest
. might helpful not use variable n
result of conversion, try num = float(num)
after checking num
"done"
.
(as homework, not post "solution", leave hints.)
Comments
Post a Comment