8. Your own while / else


#1



8. Your own while / else


File "python", line 9
if guess == random_number:
^
SyntaxError: invalid syntax


I need help, I can't figure out what is wrong with the syntax.


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
    else:
        print "You lose."
        guesses_left -= 1
else:
    print "You lose."


#2

https://www.codecademy.com/en/courses/python-beginner-en-cxMGf/0/8

This is the lesson, right?

The above should be raising an exception.


#3

statements aren't allowed within parentheses (no such pattern is known to python, it isn't able to parse it)


#6

Ok, I feel really stupid because I didn't close my parenthesis on the specified line. Problem solved.


#7

You're gonna make mistakes. You just need to figure out how to find them based on what information you have available. Ask yourself how you could have done that whenever you've spent too much time on something


#8

Just did exactly the same thing. We'll get there buddy


#9

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