8. Your own while / else - trying to make it a better game



Here is the error:
File "python", line 15
SyntaxError: invalid syntax

What do you expect to happen instead?
I expect the else statement to work perfectly fine. I don't understand why there is a syntax error. This is NOT required in the instructions but I wanted to incorporate what I've learned from other lessons. Any ideas? Thanks!

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 "Please guess a number between 1 and 10: "
    guess = int(raw_input("Your guess: "))
    if guess == random_number:
        print "Dang, you are good! That's correct!"
    guesses_left -= 1
        print "Nope, try again! You are within %s of the number!" % random_number - guess
    print "You lose."


Then do that on your own, not in the lesson. Embellishment or deviation from the instructions is never a good idea. It messes with the lesson checker, and usually introduces errors that are a disruption to the normal Q&A process intended.

For best results, stay on station with the exact exercise instructions. Once you pass the module, you can go to town, but better if you discuss your ideas and code in the Corner Bar, away from people who are just looking for code to copy so they can complete their homework faster.


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