SyntaxError: invalid syntax


#1

Hi,

I am getting same error. Please help!

from random import randint

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

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

ERROR -
File "python", line 10
if guess == random_number:
^
SyntaxError: invalid syntax


Your own while / else
#2

The error is before the point indicated. That is where parsing stopped.

Check the brackets (parens) in the above.


#3

Thanks, such a silliest mistake!

Code has resulted to infinite loop, will fix it now.


#4

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