03: Python: Syntax errors

Extend it:

Find and fix common errors in your code
Syntax errors: Find and fix common errors in your code

Debugging is intimidating to begin with because the error messages might not make much sense yet. It’s very satisfying when you can solve your own problems and even more satisfying if you can solve other people’s.

Often debugging means looking at code that you don’t fully understand yet, but the same rules we’ve used so far can still help.

Here’s some code that should draw some shapes with some syntax errors thrown in for you to find and fix:

Challenges:

Only the first of these challenges involves debugging but the other two use the same skills: using logic and creative thinking to solve a problem.

  1. Fix all of the syntax errors

    Don’t worry if you don’t recognise what the code should do: just try to run it and see where the syntax errors are then work through the steps on page 2.

  2. Write a comment for each line of code explaining what it does

    Comments can go on the line above or at the end of the line you want to explain. Just write a # then your comment.

  3. Adapt the picture to draw a rectangle

    Think through what changes you need to make to the lengths of lines and use trial and error to change the right numbers in the code.

  4. Adapt the picture to draw a house

    Think through the angles and lengths you’ll need. You might find it helpful to use a pencil and paper first.

2 thoughts on “03: Python: Syntax errors

Leave a Reply