Skip main navigation

£199.99 £139.99 for one year of Unlimited learning. Offer ends on 28 February 2023 at 23:59 (UTC). T&Cs apply

Find out more

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

Our purpose is to transform access to education.

We offer a diverse selection of courses from leading universities and cultural institutions from around the world. These are delivered one step at a time, and are accessible on mobile, tablet and desktop, so you can fit learning around your life.

We believe learning should be an enjoyable, social experience, so our courses offer the opportunity to discuss what you’re learning with others as you go, helping you make fresh discoveries and form new ideas.
You can unlock new opportunities with unlimited access to hundreds of online short courses for a year by subscribing to our Unlimited package. Build your knowledge with top universities and organisations.

Learn more about how FutureLearn is transforming access to education