how can count number of input given user in while loop?
say user enters 50 numbers. how can count number of input.
for example,
largest_so_far = none smallest_so_far = "+inf" while true: value = raw_input(">") if value == "done": break try: value = float(value) except valueerror: print "invalid input" continue if value > largest_so_far: largest_so_far = value if value < smallest_so_far: smallest_so_far = value
you can use simple counter :
largest_so_far = float('-inf') smallest_so_far = float('inf') = 0 while true: value = raw_input(">") if value == "done": break try: value = float(value) = + 1 except valueerror: print "invalid input" continue if value > largest_so_far: largest_so_far = value if value < smallest_so_far: smallest_so_far = value
the value of amount of inputs given user, minus done
. can add moving incrementation above if
.
if don't know counter is, recommend learn more before coding. how know use try
statements , no counters? have done code yourself?
using code internet not problem, need understand it. :-)
Comments
Post a Comment