Your own while/else


Oops, try again. Did you allow the user 3 guesses, or did you incorrectly detect a correct guess?

If I lose, the exercise completes correctly, but if I win, It generates the above code.

I suspect that I have the break or count decrement is in the wrong spot.

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('Take a guess!'))
    if guess == guesses_left:
        print('You win!')
    guesses_left -= 1    
    print('You lose')



if guess == guesses_left:

You should check if the user guesses equals the random number


Thank you. Not sure what I was thinking there. I didn't even realize that I was checking the users guess to see if it was equal to the number of guesses left. Crazy

Guess that's why us beginners need lots of practice.


Does it all work now and do you understand why?


yes, because I was checking to see if the users guess was equal to the number of guesses and not the generated random number.

Thank you.


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