Syntax error at Loop! (8/19)


Hi! I’m getting this Syntax error:

  File "python", line 10
    guesses_left -= 1
SyntaxError: invalid syntax

I don’t understand what i’m doing wrong with this sentences, help? Thanks!

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: "))
  guesses_left -= 1
  if guess == random_number: 
     print "You win!"
     print "You lose."     


Errors are reported when it’s no longer possible to continue, that isn’t necessarily where the mistake is.
The mistake can be something earlier in the code.

A simple (though somewhat crude) method of finding the problem is to write a separate program where you add the code one piece at a time and run it each time to see if it’s still okay.
(Or better yet, add half the code, and then either remove or add more depending on whether you’ve included the offending part yet)


I’ve got it! Thanks!


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