8. Your own while / else


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



This is the lesson, right?

The above should be raising an exception.


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


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


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


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


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