Invalid Syntax for Print Statement


#1



I'm stuck on exercise 14.8 - Your own while / else


The code looks right, but whenever I try to run it, in throws an invalid syntax error for line 11 (a print statement). In earlier exercises, codecademy was fine with the print statement instead of the function, so I used that. I tried the function too and it didn't work either.


from random import randint

random_number = randint(1, 10)

guesses_left = 3

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


#2

Point1.
guess = int(input("Your guess: ")
You missed closing parentheses ) there.

Point2.
if guess == random_number
You missed a colon : after if's condition.


#3

Thanks! I learned Ruby first, so I have a habit of leaving off colons on if statements...but the parentheses was a dumb mistake.


#4

I have a habit of leaving off colons

yeah,It happens
syntax mixups.
cheers! :slight_smile:
:thumbsup:


#5

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