Python - KS3 Troubleshooting Guide
Python - KS3 Troubleshooting Guide
If you are looking at this then you have obviously encountered some errors when running your code in the
Python Shell. Below are a list of the most common errors and the cause of them.
This guide should be able to help you identify where about in your code you have made an error and should
give you enough information to be able to correct your code so that it works!
Your error message will normally print out in the Python Shell in RED writing. The error message might contain
a section that says on which line of the code the error is located. These errors look something like this:
In this example to ensure that the code works correcty we would need to add a closing
bracket.
(Syntax Error) - Quotations opened and not closed. E.g.
In this example to ensure that the code works correctly we would need to add some
closing quotation marks before we close our bracket.
(Syntax Error) - Incorrectly names Variables. E.g.
or
In this example we have not followed the naming rules or Variables & Constants. We
CANNOT start a variable/constant name with a number and we cannot have
variables/constants with spaces in the middle. We can use number just not as the first
letter of the name.
(Syntax Error) - Missing Python Punctuation. E.g.
Missing Colon ( )
If we use a Flow Controller (if, else, while etc.) then after we have stated our specified
criteria (in this example, if number1 > number 2) then we must end that line of code
with a colon:.
(Syntax Error) - Incorrect indentation. E.g.
If we use a Flow Controller (if, else, while etc.) then we must indent all of the code that
happens Inside of that flow control so in this example we should have indented the
line of code that starts with the word print.
(Traceback Error) Calling on un-named variables. E.g.
If we try using a Variable or a Constant that we have not defined in our code then we
will receive this error, we must then go back and either declare (create it/give it a name)
this variable or correct our misspelled variable/constant.
There are many other errors that you will occur in Python but the most likely errors you will occur from
copying your code are contained above. If you have tried to fix your code and you are still not having
any luck then ask the person sitting next to you to see if they have managed to make their code work.