Skip main navigation

Debugging challenge

Have a go at fixing this script to improve your debugging skills.

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.

This article is from the free online

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

Created by
FutureLearn - Learning For Life

Reach your personal and professional goals

Unlock access to hundreds of expert online courses and degrees from top universities and educators to gain accredited qualifications and professional CV-building certificates.

Join over 18 million learners to launch, switch or build upon your career, all at your own pace, across a wide range of topic areas.

Start Learning now