Debugging

Finding out how to fix your code!

Debugging
EOL while scanning string literal

EOL while scanning string literal

Example 1


Error

Reason: this has happened as there is a missing speech marks after the string before the close bracket. IDLE will highlight the line that it is on for you.

Solution: Add the speech marks in the correct place. The change on this example is shown below:

Error

Example 2


Error

Reason: this has happened as there is a missing speech marks in the print message between the string and the variable name.

Solution: Add the speech marks in the correct place. The change on this example is shown below:

Error
Invalid Syntax

Invalid Syntax

Example 1


Error

Reason: this has happened as there is an incorrect number of close brackets at the end of the line of code. As there is two open brackets (one for the float function and one for the input function) there needs to be two at the end.

Solution: Add the bracket in the correct place. When IDLE highlights the error, it is normally on the line above where it highlights it. The change on this example is shown below:

Error

Example 2


Error

Reason: this has happened as the string in the print message has not been joined with the round function, a + or , is missing.

Solution: Add the + or , in the correct place. When IDLE highlights the error, the error is normally just before. The change on this example is shown below:

Error

Example 3


Error

Reason: this has happened as a bracket has been missed at the end of the print command.

Solution: Add the ) in the correct place. When IDLE highlights the error, it is normally on the line above where it highlights it. The change on this example is shown below:

Error

Example 4


Error

Reason: this has happened as you should have a double equals sign ==. When comparing two values in Python you must use a double equals.

Solution: Add another = in the correct place. When IDLE highlights the error, it is showing the exact location of the problem. The change on this example is shown below:

Error

Example 5


Error

Reason: this has happened as after an if statement with the condition check it should have a colon :.

Solution: Add a colon : in the correct place. When IDLE highlights the error, it is directly in front of where the red line ends. The change on this example is shown below:

Error

Example 6


Error

Reason: this has happened as a colon : is needed after the end of a line with while on it.

Solution: Add a colon : in the correct place. When IDLE highlights the error, it is directly in front of where the red line ends. The change on this example is shown below:

Error

Example 7


Error

Reason: this has happened as an else should have no condition after it. If you want to have a condition it should be an elif.

Solution: As it is the last check it should just be else:. The change on this example is shown below:

Error
NameError: name ‘variable’ is not defined

NameError: name ‘variable’ is not defined

Example 1


Error

Reason: this has happened as the variable has been used later in the program but has not been defined at the start and given a starting value.

Solution: Define the variable at the start of the code and set it to a starting value, e.g. 0. The change on this example is shown below:

Error

Example 2


Error

Reason: this has happened as the variable that you have used in line 2 doesn’t exist. IDLE lets you know what line the error is on. The if refers to mark and the user input is stored as score.

Solution: Change the name of the variable to the correct name that you want to refer to, in this case score. The change on this example is shown below:

Error

Example 3


Error

Reason: this has happened as the variable that you have used in line 6 doesn’t exist. IDLE lets you know what line the error is on. The variable defined at the start is attempts and when it is used in the code is referred to as attempt.

Solution: Change the name of the variable in line six to attempts to match the name of the variable on line 3. The change on this example is shown below:

Error
expected an indented block

expected an indented block

Example 1


Error

Reason: this has happened as the code that is to be executed inside a loop must be indented.

Solution: Indent the code that you want to execute inside the loop. The change on this example is shown below:

Error

Example 2


Error

Reason: this has happened as the code that is be executed after an if must be indented.

Solution: Indent the code that you want to execute if the condition is met under the if. The change on this example is shown below:

Error

Example 3


Error

Reason: this has happened as the code has not been correctly indented. The code for the while loop is indented correctly, however there needs further indentation for code under the if.

Solution: Indent the code that you want to execute if the condition is met under the if. The change on this example is shown below:

Error
TypeErrors

TypeErrors

Example 1


Error

Reason: this has happened as on line 4 it has tried to use height in a calculation, but height is stored as a string, the data type of height is a string.

Solution: convert the input to a float or int so it is considered a number and can be used in calculations.

Error

Example 2


Error

Reason: this has happened as on line 5 as it has tried to use height in a print command. It is joining a string with a float and therefore it gives an error. All variables in a print command must be converted to a str() to prevent the error.

Solution: convert the variable height to a string str(height) in the print command.

Error
TypeErrors

IOErrors

Example 1


Error

Reason: this has happened as the file that is trying to be read cannot be found. This means that the .csv file is not in the same folder as the Python program.

Solution: make sure the .csv file that you are trying to read is in the same folder as the Python program.

Error
If you need to get in touch with Mr McG then this is the way….

What's your name?
image/svg+xml
Thank you [name], that's great.

Can I ask where you are from?
image/svg+xml
Hey [name], can I ask where you are from?
image/svg+xml
Hey [name], which class are you in?
image/svg+xml
OK [name], thanks for that.

I will need your email address so I can get back to you!!
image/svg+xml
Thanks [name], nearly there.

What can I help you with?
image/svg+xml

Thanks [name] from [whichclass][location], Mr McG will get your message…"
[message]"…and will get back to you ASAP via [email]. Catch you soon.

image/svg+xml
Thank you [name], Mr McG got your message.
Thanks [name], Mr McG will get back to you as soon as he can!!

Have a great day!!

K McGuinness - 2018

No personal data will be shared with any third party. The only data processed via this website is anonymous browsing data to best manage your user experience.