Your own while/else


#1



https://www.codecademy.com/courses/python-beginner-en-cxMGf/0/8?curriculum_id=4f89dab3d788890003000096#

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

To allow three guesses and if three wrong then "You Lose"


from random import randint

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

guesses_left = 3
while guesses_left > 0:
    guess = int(raw_input("Your guess: "))
    
    if guess == random_number:
        print "You win!"
        break
    elif guess != random_number:
        guesses_left -= 1
        break;
else:
    print "You lose."
    # Start your game!


#2

# Generates a number from 1 through 10 inclusive
random_number = randint(1, 10)
print "All right, you wanna play Guess the Number?"
wanna_play = (raw_input("Wanna play? "))
print "I didn't really hear you, but I don't care."
print "I'm gonna choose one number between 1 and 10. You HAVE to guess."
guesses_left = 3
# Start your game!
while guesses_left >= 1:
    guess = int(raw_input("Your guess: "))
    if guess == random_number:
        print "You guessed right. You win, I guess."
        break
    else:
        print "Wrong."
        guesses_left -= 1
else:
    print "Game over. You lose. Ha!"

This thingy worked for me.


#3

The error lies in your elif statement. We put a break after if because we want to break the loop (the user guessed correctly). However, if we put a break after the elif statement, it disallows the loop to continue. Basically, delete the break from the elif statement and the loop will continue until the guesses_left variable does in fact=0.