Your own while / else


#1



So this is throwing an error that I can't seem to suss out
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:
    guesses_left -= 1

else:
print 'You lose.'

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


Replace this line with your code.


#2

When you are grabbing your raw input you forget a parentheses.
Corrected code:

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

#3

Hello! I am stuck at this same place.
My code is below, can anyone please help!!

from random import randint

Generates a number from 1 through 10 inclusive

guess = random.randit(1,10)
guesses_left = 3

Start your game!

while count > 0:
guess = int(raw_input("Your guess: "))
if guess == random.randit(1,10):
print "You win!"
break
guesses_left -= 1
else guess < 1:
print "You loose"


#4

Looks like you spelled randint "randit"


#5

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