Your own while / else


#1



https://www.codecademy.com/courses/python-beginner-en-cxMGf/0/8?curriculum_id=4f89dab3d788890003000096#


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


#2

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


#3

what does it mean to decrement guesses left?


#4

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


#5

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


#6

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