Your own while / else


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

But i can't see where the error is..? x.x help!

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!'
    guesses_left -= 1
    print 'You lose.'


Because you have to methods on this line you need to have two closing parentheses after the string not one,

should be,

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

#Extra parentheses to wrap int() and raw_input() methods


what does it mean to decrement guesses left?


ah, oh yea.. thank you! :slight_smile:


guesses_left = 3 at first, and after each wrong guess, the guesses_left should decrease by 1. Decrement would just mean to decrease the value by 1 in each loop.. (i think? XD)
The code to decrement would be:
guesses_left -= 1


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