Your own while / else Help!


#1


It reminded me "Something went wrong......", but I don't know and cannot find where the wrong place was.I wonder if the system is wrong.


#2

And it reminded that a invalid syntax in line 9


#3

what do you enter when you are prompted for input by raw_input?

Can you copy paste your code to the forum so i can run it?


#4

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."

#5

here:

else:

whatever you use after else, its not a colon. It looks like one, but it isn't. use a colon


#6

Thank you so much, I was confused for a long time. I just messed the Chinese input method and the English input method up. It's so ignoring! Thanks a lot!


#7

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