Ask coding questions

← Back to all posts
I neeed help plzzz
PythonLearner99 (0)

This is for a school project and it is saying there is a syntax error when I think there is nothing wrong could I please get some help fixing it?

Answered by IMayBeMe (346) [earned 5 cycles]
View Answer
Comments
hotnewtop
IMayBeMe (346)

The issue is that (score + 1) doesn't work, switch it to score += 1.

Zavexeon (1159)

To further elaborate.

(score + 1) simply returns whatever score plus one is, for example, if score is 2, (score + 1) evaluates to 3.

However, this does not actually set score to 3. It only evaluates to 3, so for example (score + 1) == 3 would be true, however score == 3 would be false.

In order to add 1 to score and to set it to the new value, which is called incrementing, you need to set the score to itself plus 1.

The obvious way is score = score + 1, however in Python (and most other languages), you can actually shorten it to score += 1.

The operators -=, /=, and *= also exist.

I am going to mark @IMayBeMe as the answer.

PythonLearner99 (0)

@Zavexeon
yeah umm there is another problem it is with an else statement and I have no clue about what to do

IMayBeMe (346)

@PythonLearner99 Ok so the issue on the else statement is that your code looks like this, else: print("You are wrong."), but in reality the issue is the and else: statement can't be on the same line as function your calling which in this case is print("You are wrong.") So to fix this you would put the print on the next line and indnet it like so:

else:
  print('You are worng.')

Also on a side note if you were wondering about the single quotes on the correct code which I put, its just a faster way of putting quotes in python

PythonLearner99 (0)

@IMayBeMe
That still did not work for some reason

IMayBeMe (346)

@PythonLearner99 You didn't indent the print that comes after, indent it by using tab

PythonLearner99 (0)

@IMayBeMe
maybe it didn't save because it says the else: statement is wrong

IMayBeMe (346)

@PythonLearner99 Oh that's probably because your (score += 1) should not have any parentheses around it.

PythonLearner99 (0)

@IMayBeMe
So I did that but it still says there is a syntax error with else

PythonLearner99 (0)

@IMayBeMe
I have now done that but it still says there is a syntax error with the first else: statment

IMayBeMe (346)

@PythonLearner99 I'm not sure if this is the issue but,
indent the score += 1 and also put it exactly how I typed it cause you still have score = (0 + 1) which doesn't work

LukeWright (114)

I don't see a syntax error. Where is it giving the error?

PythonLearner99 (0)

@LukeWright
I kinda removed most of it so yeh now there is now syntax error but now it doesn't work