Your own while / else


#1
from random import randint

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

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

This gives an error:

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

Can anybody point out where I went wrong? Thanks.


#2

try taking the raw_ from raw_input out and leaving it as input

guess = input()

#3

Hi lokixviii, thanks for your reply. I tried, but it doesn't work:

File "python", line 10
    if guess == input():
                       ^
SyntaxError: invalid syntax

The Hint section includes: "The if should check if guess == random_number."


#4

You need to put second ')' at the end of previous string:

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