Debugging challenge

Last week you started to look at ways in which to debug code that’s not working. This week we’re going to step it up a little.

The code below contains several errors, and you’ll need to find them all before it will run correctly. All the errors are in the loop, so you can trust that the first three lines are correct.

Try running the code and then looking at the errors reported in the shell. Don’t forget to read the errors from the bottom upwards, and then fix them one at a time.

names = ['Alice', 'Bob', 'Carol', 'Dan', 'Eve']
ages = [22, 32, 18, 57, 41]
current_year = 2017

for person in range(6)
    age = ages(person)
    name = names[person]
    year_of_birth = age - current_year
    print('name' + ' was born in ' + year_of_birth)

How many errors did you find? Share your successes and failures in the comments below, and don’t hesitate to ask the other learners for help if you need it.

Share this article:

This article is from the free online course:

Scratch to Python: Moving from Block- to Text-based Programming

Raspberry Pi Foundation