8. I think my game works fine but it isn't being accepted *solved*


#1



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


The game works as intended and includes an 'else' but I'm getting "Oops, try again. Did you include an else for the while loop?"


from random import randint

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

# Start your game!
print "Guess the golden number for amazing prizes!"
while guesses_left > 0:
    guess = raw_input("What is your guess?")
    guesses_left = guesses_left -1
    if guess == random_number:
        print "You win!"
        break
    elif guesses_left > 0: 
        print "Unlucky, try again"
    else:
        print 'You lose.'
        break


#2

The else should go after the while loop.

E.G.:

while myVar == True:
    #Blahblahblah
else:
    print "The condition in the while loop was False."

#3

Thanks, it works fine now


#4

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