How can I eliminate this infinite loop? 14/8 Your own while/else


#1

Hi, I am unable to get rid of this infinite loop and I would greatly appreciate help. Here is my code:

from random import randint

# Generates a number from 1 through 10 inclusive
random_number = randint(1, 10)

guesses_left = 3
guess = int(raw_input("What's your guess?"))
while guesses_left > 0:
    if guess == random_number:
        print "You win!"
        break
    else:
        print "Guess again."
        guesses_left -= 1
else:
    print "You lose."

And here's what the interpreter gives me:

What's your guess? 3
Guess again.
Guess again.
Guess again.
You lose.
None

It takes 3 as the guess for all 3 turns. Help would be greatly appreciated - thanks!


#2

Never mind. I kept working on it and solved it. Thanks if you were willing to help though.