8/10 invalid syntax


#1
   File "python", line 10
if guess == random_number:
                         ^

SyntaxError: invalid syntax

from this submitted code.

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('Your guess: ')
        if guess == random_number:
            print 'You win!'
            break
        guesses_left -= 1
        if guesses_left >= 1:
            print 'guess again'
        else:
            print 'you lose'

I'm pretty new to coding but this seems fine to me, but just want to clarify that it is the site and not me :stuck_out_tongue:

Thanks


#2
while guesses_left > 0:
    guess = int(raw_input("Your Guess: "))
    if guess == random_number:
        print "You win!"
        break
    else:
        guesses_left -= 1
        print "Guess Again."
else:
    print "You lose."

#3

I had the same issue. Looks like you need a second ")" after the "('Your guess: ')"


#4

As others have pointed out, you will always need to close brackets, quotes, double-quotes and in this particular case, parenthesis.

You are getting this error message with the "^" pointing at the ":" because you called int() and forgot to close its parenthesis pair. The pair acts as delimiters of what should be evaluated as a type integer.

The python interpreter is then trying to evaluate anything it will find up to the closing parenthesis and up to ":" it was so far so good but as int but stumbles on ":" it just tells you "I just don't know what to do with this thing"

Sometimes the error happens to be exactly what the "^" is pointing at but most of the time it will be on previous lines and you will have to use your eagle vision as you track back and seek for unclosed pairs or missing colon :stuck_out_tongue:


#5

LOOOOL Thanks guys, even though I'm new shocked I over looked something that is pretty much a across the board rule.

Consider me humbled. xD