Why doesn't this break work in a while loop?



I set it up so that I know what random number is. And so I type in the answer when asked to, and then my loop keeps on going. It doesn't break.

I expected the loop to break, since my answer is equal to the random number generated, wnich is printed before I am asked for answer.

from random import randint

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

guesses_left = 3
# Start your game!
while guesses_left > 0:
    print random_number
    guess = raw_input('Make your guess!')
    guesses_left -= 1
    if guess == random_number:
        print 'You win!'
    print 'You lose!'


guess is a string, where as random_number is a integer. Lets see what happens:

if "2" == 2:
    print "string and integer are equal"
    print "string and integer are not equal"


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.