Unit 8: Lesson 8: Your own while/else


#1



I am stuck with exercise 8 in the 8th unit.


Why am I getting this error?
File "python", line 11
if guess == random_number:
^
SyntaxError: invalid syntax


I expected this syntax to be correct and my if statement to be evaluated


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:
    print guesses_left
    guess = int(raw_input("Your guess: ")
    if guess == random_number:
        print "You win"
        break
    guesses_left -= 1
else:
    print "You lose"


#2

Hi this line

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

you didn't close the int()


#3

Thank you! I knew there was something silly I must have overlooked.


#4

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