i’m relatively new to coding and i’m coding a simple text based game. while i was testing the code this syntax error came up. i tried to fix it by encasing the line in brackets, it stopped telling me there was an error but it the same exact problem happened on the next line. the brackets on the previous line are there because when there was a colon, it told me it was a syntax error. can anyone help me?
Please do not post text in images:
Why should I not upload images of code/data/errors when asking a question?
Put your code, commands, output, error messages as text between lines with triple backticks:
``` Your text will be here. ```
In this case we are missing the error traceback which provides a lot of useful information. Please show it unabridged.
About what I can see in the image:
- The operator
()is used to call functions. Integers are not functions, they are not callable so the sub-expression like
2()should correctly give you the exception
TypeError: 'int' object is not callable.
- Compound statements like
whilerequire a colon to end its “header”. See 8. Compound statements — Python 3.10.8 documentation
Example of the use of the
if precipitation_mm_h > 50: print('Violent rain')
I’m using python 3.9.9 and i put a colon there but it just highlighted in in red and told me “Syntax Error” when i tried to run the programme.
2() that’s confusing it. Sometimes the real mistake is before where it thinks it is.
To put it more explicitly: In the line with the
if statement in your image you have at least two errors:
- You are trying to call integer
2as a function.
2()is invalid in Python.
ifstatement header line is not terminated by the obligatory colon character
It is not Python interpreter highlighting parts of your code in red. It is your editor. It is probably using some linter to detect possible problems.
Python interpreter will show you possible error message after you run your code. This forum is about Python so we are much more in interested what Python interpreter shows you instead of what an unknown editor shows you.
If you are not sure how to run your Python program - let’s say you saved it in a file named
game.py - do the following:
- Open command line of your operating system.
- Change to the directory with your
- Run one of the following commands. Unfortunately the variant depends on the operating system and the way Python is installed
Someone should finally point out the real original error…
if port_action == 2: print("  hull") print("  engine") print("  radar")
This STILL does not work!
So remove all of that and finally track down the real original error. Really not hard. Just remove more and more code until you find it.
print("  West") print("  display map") nav_action = int(input("what do you want to do?")
“unexpected EOF error, while parsing” past the last bracket
How many opening parentheses are there on the last line? And how many closing parentheses?
thank you im just blind