Your own while / else (syntax error?)


#1



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


For some reason, my code gives a syntax error on line 10. I have no idea how, it changes color (shows in bold here), has a variable and a condition, and an indent for the rest of the code. What am I missing?


I'm trying to get the loop to work, and I've even copy-pasted other functioning scrips in my own (of course after verifying that I've done it correctly), but it still says I'm doing something wrong.


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("Guess my number... ")
    if guess == random_number:
        print "You win!"
        break
    guesses_left -= 1
else:
    print "You lose."


#2

Missing a closing parenthesis for int().


#3

... facepalm I'm a genius. Thanks for pointing that out! It's all good now.


#4

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