[Tutor] command error
Sander Sweers
sander.sweers at gmail.com
Tue Feb 16 21:55:47 CET 2010
On 16 February 2010 21:32, Shurui Liu (Aaron Liu) <shurui91 at gmail.com> wrote:
> Here is a program I wrote, I don't know why I cannot exit when I tried 10
> times? Hope somebody can help me. Thank you!
>
> while (guess != the_number):
> if (guess > the_number):
> print ("Lower...")
> print ("You were wrong, try again", tries, "times left.\n")
> else:
> print ("Higher...")
> print ("You were wrong, try again", tries, "times left.\n")
>
> guess = int(raw_input("Take a guess: "))
> tries -= 1
This will loop untill guess == the_number with no other way out.
Meaning unless the number is guessed it will end up in an infinite
loop. You will have to figure out how to *break* out ot the while loop
when tries == 0.
Greets
Sander
More information about the Tutor
mailing list