largest_so_far = None
smalest_so_far = None
value = float(raw_input(">"))
while value != ValueError:
value = float(raw_input(">"))
if value > largest_so_far:
largest_so_far = value
elif value == "done":
break
print largest_so_far
I think problem with this is that done is string while input is float type.
I have also tried it running using value = raw_input(">")
instead of float(raw_input(">")
but that prints the result as done
I would do this as follows:
Few hints:
Instead of converting the user input to
float
immediately, why don't you check if it isdone
first?Since you are going to do this forever, until user enters
done
or there is a value error, use an infinite loop and atry..except
, like thisEdit: The edited code has two main problems.
The
continue
statement should be within theexcept
block. Otherwise, the comparisons are always skipped at all.When you compare two values of different types, Python 2, doesn't complain about it. It simply, compares the type of the values. So, in your case, since you assigned
largest_so_far
asNone
, theNoneType
is compared with thefloat
type.Since, the
float
type is always lesser thanNone
type, the conditionis never met. So you will be getting
None
. Instead, usefloat("- inf")
like I have shown in my answer.