Modifying an existing Python program
Read a working program, then change one part, like a value, condition or message, to get new behaviour. Predict the result first, change one thing at a time, then run it.
Understanding Modifying an existing Python program in Years 7–8 Creating Digital Solutions
What it does: Only the name in the message was changed, so if the output is different you know exactly which edit caused it. The second print() line is a new feature added to a program that already worked, so it now shows lives as well as score. Modifying code means changing one part of a working program, like a value, to get new behaviour. Predicting first helps you check that you understand the code. If the result is different, you learn something. Changing one thing at a time makes it easy to find which change caused a problem. The condition decides when the code runs. Changing the condition changes when the player wins. Changing the message only changes the text.
Common mistakes: Python is case-sensitive. The variable is called bonus, not Bonus, so this causes a NameError. When you change code, keep variable names exactly the same: score = score + bonus. When you change a message, keep the comma between the arguments in print(). It should be print('Lives left:', lives).
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 50–125) and word search (Modules 3–125).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
modify codeFill in the Blanks
Spot the Error
Student with a class code? Join your class →