import random number = random.randint(0,10) counter = 1 guess = input ("Guess a number between zero and ten. ") if guess == 0: print number if guess == 11: guess = number if number == guess: print "Good guess!" quit() else: while counter <= 5: counter = counter + 1 print "Guess no.", str(counter) + ":" guess = input ("Try again! ") else: print "Game over."
As you see, I added two "hacks" that can be used when the program asks the first question. The problem is, even when I type in the known correct answer, the program tells me to try again. Answering "11" to the first question or "0" when it's the right answer have been the only ways to win when using random integers (so it seems that the program structure is correct).
The program also works when I assign a specific value to the variable "number" and then type it in.
So far I've tried declaring "guess" global when it's assigned inside the loop (and noticed it's not necessary) and changing line 11 to
if int(number) == guess:
I think this is weird, as I have used random integers before without any problems.
This post has been edited by KorvusKoraks: 02 August 2011 - 01:23 PM