8/19 Syntax Error


#1

In my code, I typed:

if guess == random number:
print "You win!"

It gives me a syntax error. Here's all of my 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
    else:
        print "You lose."

#2

Have you noticed the indentation of print "You win!"?


#3

what do you mean. Shouldn't it be indented?


#4

Em... Excuse my English.
I mean it should be indented with 4 spaces, not with a '\tab'.
Mixing blank space and '\tab' in one line is a common error, and using blank space only is a good habit.
Hope it will help.
Enjoy Python : )


#5

It's still not working. It's just the if guess == random_number: part.


#6

I think you lose ) in line 9


#7

I know. I figured it out a while ago.


#8

guess = int(raw_input("Your Guess: ")
look at this one more time, something's missing

guess = int(raw_input("Your Guess: "))


#9

:grin::+1::sweat_smile: You may have not realized this but you said “I figured it out a while ago” :grin::+1::sweat_smile: