Monday, 15 February 2010

python - breaking out of the loop? -



python - breaking out of the loop? -

i'm having problem breaking out of these loops:

done = false while not done: while true: print("hello driver. travelling @ 100km/h. please come in current time:") starttime = input("") try: stime = int(starttime) break except valueerror: print("please come in number!") x = len(starttime) while true: if x < 4: print("your input time smaller 4-digits. please come in proper time.") break if x > 4: print("your input time greater 4-digits. please come in proper time.") break else: break

it recognizes whether number < 4 or > 4 when number inputted 4-digits long returns start of programme rather continues next segment of code, isn't here.

you want utilize variable done flag. have set before lastly break (when done).

... else: done = 1 break

python loops

No comments:

Post a Comment