Python - KS3 Troubleshooting Guide

Embed Size (px)

DESCRIPTION

A small guide designed to help Key Stage 3 students identify some of the simple errors that they have made within their Python 3 program code.

Citation preview

  • Troubleshooting my Code 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:

    As you can see on the second line of the error it says

    File, line 1

    This is referring to line 1 of your code. You can see which line of your code your cursor is

    currently on in the design view of Python IDLE by looking in the bottom right hand corner of

    the window.

    Most common errors you will occur - Syntax Errors

    These errors occur when there is some form of mistake in the language used within the code.

    Just like we wouldnt spell Horse with a bracket in the middle [Hor(se], Python expects you to

    follow its language rules as well.

    The following things will bring up Syntax Errors in Python:

    (Syntax Error) - Brackets opened and not closed. E.g.

    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.

    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.

    Missing Colon (:)

    We have not indented here

    when we should have!