Weird Syntax Error

Page 1 of 1

2 Replies - 584 Views - Last Post: 14 February 2013 - 01:05 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=312253&amp;s=f3a9deda39fc6994bec6c6826cde97f7&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 AbbKazPow

Reputation: 0
• Posts: 4
• Joined: 08-February 13

Weird Syntax Error

Posted 14 February 2013 - 12:49 PM

This code isn't working...
For some reason there's a syntax error where I've highlighted with comments
```from random import randrange
print """This is going to be the hardest game ever.
You, the lowly player, have to think of a random whole number between 1 and 100.
I, the supreme computer, will guess the number at random."""
compGuess = randrange(100)+1
nowGuess = compGuess
tries = 1
def repeatFunc():
global highLow
highLow=raw_input("My guess was: "+str(compGuess)""". Is this too high or too low?
Or are you too scared to tell me the truth? Tell me either "high", "low" or "correct" exactly the way I have told you.""")
repeatFunc()
while highLow != "correct":
if highLow == "high":
while compGuess <= nowGuess : # the syntax error is at the nowGuess on this line
compGuess=randrange(100)+1
tries += 1
elif highLow == "low":
while compGuess >= nowGuess:
compGuess = randrange(100)+1
tries += 1
repeatFunc()
print "Ha ha. I have beat you. Of course, it only took me", tries, "tries. Newbie."

```

Can you please tell me why there is a syntax error?
This is really annoying me.

Is This A Good Question/Topic? 0

Replies To: Weird Syntax Error

#2 darek9576

• D.I.C Lover

Reputation: 203
• Posts: 1,731
• Joined: 13-March 10

Re: Weird Syntax Error

Posted 14 February 2013 - 01:00 PM

Dont use global variables. Just return the number from the function and assign it to a variable.

#3 andrewsw

• blow up my boots

Reputation: 6544
• Posts: 26,525
• Joined: 12-December 12

Re: Weird Syntax Error

Posted 14 February 2013 - 01:05 PM

If you are using Python 3 then the print function requires brackets:

```print("Print this.")
```

Although you can use triple-quotes, like this
```print("""Print this.""")
```

this seems unnecessary and confusing. Most would reserve these triple quotes for docstrings.

```def my_func():
```

Your raw_input() use in particular is mis-typed, not finished correctly. Perhaps you intended """Is this too high or ..""" to be a comment? In which case, finish your input with a closing bracket and use the hash-sign for your comment.

darek9576, on 14 February 2013 - 01:00 PM, said:

Dont use global variables. Just return the number from the function and assign it to a variable.

While this is good advice it doesn't attempt to resolve the OPs stated problem - the syntax error(s).

This post has been edited by andrewsw: 14 February 2013 - 01:06 PM