Your own while / else


What is wrong with my code here?

it keeps telling my I have a syntax error on my if statement where the colon is.

from random import randint

# Generates a number from 1 through 10 inclusive
random_number = randint(1, 10)

from random import randint
guesses_left = 3
while guesses_left > 0: 
    print "Guess Again"
    guess = int(raw_input("Your guess?")
    if guess == random_number:
        print 'You win!"
        guesses_left - 1
    print "You lose."


After reviewing my code I see I have a not used the correct number of brackets above! Woops typo!


you need to use markup to make indent show:

i see several problems:

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

look at the parentheses.

print 'You win!"

an apostrophe doesn't match with a quotation mark

guesses_left - 1

this won't updated the guesses_left variable


Oh thanks for the format, and I actually just came back to answer my one question!

I saw the two errors after posting, I have a questions for you.

is there any difference in creating a string using ' ' or " "?


no, the only difference is:

print 'see "this" works fine'
print "this 'also ' works"


print "now i have to \"escape\""
print 'and \'also\' escape here'

that is the most important difference. So if you have a string in which you need to print a lot of ' or ", make sure to use the right thing


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