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:
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.
- 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.
- 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.
- 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.
- 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.
Page 1: Intro
Page 2: The theory: learn what you need to know as fast as possible.
Page 3: Try it: try out and adapt some working python code snippets.
Page 4: Debug it: Learn how to find and fix common mistakes.
Page 5: Extend it: Choose a project idea to use your newfound python skills.
Amazing! You are helping me to feel more confident in teaching Python! Thank you, and keep up the great work!