8. Your own while/else, storing user guess in variable


Hey guys, I'm stuck at 14.8, namely "Your own while/else".

Whenever I submit the code, the code-thing window simply says "You lose." (and of course "None"), without giving the user a chance to guess the lucky number.
The error message reads: "Make sure you store the user guess in a variable called "guess"."

The full code looks like this:

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 guess == random_number:
        print "You win!"
    print "You lose."
    guesses_left -= 1


i think you didn't indentat the else statement correctly !! have to be at same level of if


That's not it, because it's supposed to be a while/else, not if/else. Also if I do that, I instead get the message "Did you include an else for the while loop?".
Thanks for the help, though :slight_smile:


Yeah, thanks for the quick reply :smiley:
I think your condtion is not correct guesses_left < 0


Ahh yes, thats the one. Works now, thanks a ton for the fast help! :smiley:


put the statment :
while guesses_left > 0:

and put "guesses_left -= 1" inside the while loop not in else.
that should work, i did form me :slight_smile: