8. Your own While/ Else


#1

from random import randint

random_number = randint(1, 10)

guesses_left = 3

while guessesleft > 0:
guess = int(rawinput("Guess a # 1-9:"))
if guess == randomnumber:
print "You win!"
break

else:
print "Try again:"
guessesleft -= 1
else:
print "You lose."

I did indenting and I get this

File "python", line 13
else:
^
SyntaxError: invalid syntax


#2

Your variables need to be seperated by underscores. Example:

my_variable = "Cade"

#3

THANKS SO MUCH! THAT Helped so much


#4

Wait I just tried that and I got

File "python", line 13
else:
^
SyntaxError: invalid syntax


#5

I assume that your whitespace is wrong.


#6

what is that? White space what is that?


#7

It is how Python distinguishes functions. After a colon, you must have whitespace (Four spaces or tab). Example:

def print_cade():
    for num in range(1, 100):
        print "Cade"

print_cade()

#9

NVM found out :slightly_smiling:
the answer


#10

which one is it i am getting mad on this exercise


#11

Sorry, but not going to give you a free answer. :slightly_smiling:


#13

I'm not sure if you've had more help with this, but there needs to be an "if" statement in the code as shown in the example, this isn't very clear in the instructions, I suspect it's assumed that one will follow the screenshots verbatim in this one unlike many others in the course.