Your own while / else


#1

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!"
        break
    else:
        guesses_left - 1
else: 
    print "You lose."

#3

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


#4

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


#5

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


#6

no, the only difference is:

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

and:

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


#7

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