Lecture 7: Understanding and fixing problems in python code#

It’s normal. You’ve just finished writing that new bit of code. You’re certain that you’ve done it right, but when you run it, it fails or doesn’t give the right output. What can you do to try to get the code working again? In this notebook we introduce some steps that can normally be used to try to identify, and fix, the problem.

We will explore some examples of debugging python code in today’s class, demonstrate the use of some tools like PDB, and try to give you more confidence in understanding and fixing problems that will always arise in your code.

We will then show a number of examples of broken code where you will have to identify and fix the problem.

WARNING This is a lecture in debugging, so all errors I made while putting this content together have been deliberately left in the code .. Enjoy!

Weekly tasks#