This forum is now read-only. Please use our new forums! Go to forums

banner
Close banner
0 points
Submitted by Deyva
over 11 years

I am getting a syntax error for correct code?

I am currently doing 1.8 ‘Your own While/Else loop’ and when I run the code I get this error:

Traceback (most recent call last):
  File "runner.py", line 96, in compilecode
  File "python", line 8
    if guess==random_number:
                           ^
SyntaxError: invalid syntax

The code is:

from random import randrange
random_number = randrange(1, 10)
count = 0
while count < 3:
    guess=int(raw_input('Enter a guess:')
    if guess==random_number:
        print "you win!"
        break
    count+=1
else:
    print'you lose.'

I really have no idea what’s wrong with this code, can someone please help explain?

Answer 50a4f31c52ffbff3fd006059

0 votes

Permalink

You forgot to close the bracket you opened here:

guess=int(raw_input('Enter a guess:') # missing )

This is what causes the error. Also, you might want to change 'you lose.' to 'You lose.' in order to pass the test.

points
Submitted by Alex J
over 11 years

1 comments

Deyva over 11 years

sweet, it’s all good now, thanks for the help.