Looping through lists – Year 9 Computing lesson
Pupils learn to append items to a list and traverse it with a for loop to print, count or total every item.
Lesson 3 of 6 in unit 9.1 Python: Lists and Functions, taught in Year 9, Autumn 1. It answers one big question: How can a program visit every item in a list?
By the end, pupils can append items to a list and traverse it with a for loop to print, count or total every item.
- The Build (the main task)
- Write a program that asks for four new game scores, appends each one to a list, then traverses the list to print every score and the total.
- Support version
- Part-filled code: the loops are given, with gaps for the append line and the line that adds each score to the total.
- Challenge
- Traverse the list again to find the highest score without using max(), and print how many scores are over 50.
- Real-world link
- Each new game adds a score to the end of the leaderboard, and the app works out totals by visiting every score in turn.
- Key words
- Traversal, Append and Access, each with a definition, an icon and a common mix-up on the key vocabulary slide.
- Misconceptions it tackles
- “In for score in scores:, score is the position number of each item”; “append can add an item at any position, such as the start of the list”.
- National Curriculum
- NC3 (two or more languages, at least one textual; data structures; modular programs with procedures or functions).
Every lesson follows the same Code & Commerce structure: a Bell Task recall starter, key vocabulary with definitions and icons, short teaching chunks with a check before pupils move on, The Build (one main task), challenge questions that get harder, and an exit question. Answers reveal one at a time on the slides, and everything is editable PowerPoint and Word.
Pupils need computers for the main task.
- Also sold in the Python
- Lists and Functions unit bundle, which includes the medium term plan, and in the full-year and complete-course bundles.
What's included
- Slide deck (PowerPoint)
- Lesson plan (Word)
- Worksheet (Word)
- Support worksheet with scaffolds (Word)
- Single-teacher licence: use and adapt it with your own classes
More for KS3 Computing
See allPupils learn to trace a program that uses a loop and nested selection in a trace table, and use it to predict the program's output.
Free sample lessonPupils learn to create a list, access and change an item using its index, and find how many items it holds with len().
Pupils learn to define and call a procedure and a function, and explain that a function returns a value but a procedure does not.
Written for the specifications named. Not endorsed by or affiliated with any exam board.