How could this code pass?


#1



I keep trying to get it to say "You Win" but it just prints out the same random number 3 times in a row. Yet, codeacademy still lets me finish it. Am i missing something?


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:
    guess = int(raw_input("Your guess: "))
    if random_number == 5:
        print "You Win!"
        break
    print random_number
    guesses_left -= 1 
else:
    print "You lose."


#2

We are to compare the guess to the random_number.

That line should be removed.


#3

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