Community resourceWorksheet

Y9-L02 Lists and loops: build your playlist

Part 2 of 3 · Y9 Lists

Pupils use lists and for loops to collect track titles, edit list items, and print the final list and its length. It teaches list indexing, appending, loop control, indentation, and a simple safety check before removing an item. The worksheet is fairly accessible, but it builds towards an independent programming task and is moderately demanding.

Shared by Mr HopkinsonVerified teacher

  • 23 cells
  • CC BY-SA 4.0
  • Shared 12 Nov 2026

Preview

The whole resource, exactly as a class sees it. Answers and marking are held back.

Lists and loops: build your playlist

Use lists to store and change track titles. Learn to repeat input and append with a for loop, then build your own playlist.

List reminders

An index is an item’s position number. The first index is 0.

CodeJob
tracks = ["Glow", "Orbit"]Create a list: square brackets, commas between items, quotes around text
tracks[0]Access the first item using its index
tracks[0] = "Spark"Access the first item and assign a new value
tracks.append("Echo")Add a new item at the end
tracks.remove("Orbit")Remove the first item with this value
tracks.pop(1)Remove the second item, at index 1
len(tracks)Count how many items are in the list

Task 1: Warm up your playlist

A. Fill three gaps. Access and print the first title. Remove index 1, then print the list’s length.

B. Run and check. Expect Glow, then 3.

Fill in the code3 marks
tracks = ["Glow", "Orbit", "Home"]
tracks.append("Echo")
print(tracks[Gap 1])
tracks.Gap 2(1)
print(Gap 3(tracks))
  • remove
  • 1
  • len
  • append
  • 0
  • pop

Repeat a set number of times

A loop repeats code. One repeat is an iteration.

for turn in range(3):
    print("Next track")
print("Playlist ready")

range(3) makes this loop repeat three times. Change the number to change the repeats.

Indentation means spaces before code. Use four spaces for lines inside the loop. Keep : after the for line.

The last print is outside the loop and runs once.

Repeat three times, then finishrange(3) repeats the indented line three times. Playlist ready is outside the loop and prints once afterwards.Inside: 3 repeatsFirst timeSecond timeThird timeNext trackNext trackNext trackAfter: Playlist ready — once

Task 2: Complete a for loop

A. Fill three gaps. Repeat Next track three times.

B. Run. Check that Playlist ready appears once, after the repeats.

Fill in the code3 marks
Gap 1 turn in Gap 2(Gap 3):
    print("Next track")
print("Playlist ready")
  • 3
  • if
  • range
  • 4
  • for
  • len

Task 3: Change the repeats

A. Edit: print Next track four times.

B. Move: print Playlist ready once, after the loop.

C. Run and check.

Loop reminder

Change the number in range(). Remove indentation from code after the loop.

Coding task2 marks
for turn in range(2):
    print("Next track")
    print("Playlist ready")

Add one reply each time

Create tracks = [] before the loop. Inside: take input → store the reply → append it.

In input("Track title? "), the text is the question. You type the reply when it runs.

Task 4: Collect three track titles

A. Add a for loop to collect three titles. Inside: take input into track, then append it to tracks.

B. Run and check with Glow, Orbit, Home, one at a time.

Input and append
track = input("Track title? ")
tracks.append(track)

Indent both lines. Use track without quotes.

Coding task3 marks
tracks = []
# Add a three-repeat loop: take input, then append.

print(tracks)

Task 5: Keep the earlier titles

What goes wrong if tracks = [] is moved inside the Task 4 loop, before input()? Write one short sentence.

Written answer1 mark

What would happen to the titles already added?

Students type their answer here.

Check before removing

if name in tracks: checks whether the title is in the list. Only remove it if it is there; removing a missing value causes an error.

Task 6: Polish the list

A. Fill three gaps. Access the first item and assign Spark. Remove Orbit if present. Print the list and its length.

B. Run. Expect ["Spark", "Home"], then 2.

Fill in the code3 marks
tracks = ["Glow", "Orbit", "Home"]
tracks[Gap 1] = "Spark"
name = "Orbit"
if name in tracks:
    tracks.Gap 2(name)
print(tracks)
print(Gap 3(tracks))
  • pop
  • len
  • 1
  • remove
  • 0
  • append

Task 7: Plan your own program

Write short notes.

A. Collect: where does the empty list go? How will you add three replies?

B. Afterwards: how will you replace the first title, safely remove a title, and print the list and its length?

Written answer2 marks

Write your plan for parts A and B.

Students type their answer here.

Task 8: Build your playlist

A. Collect.

Create tracks = [] before a for loop with range(3). Inside: take input into track, then append it.

B. Edit after the loop.

  • Take input into new_first; assign it to tracks[0].
  • Take input into remove_track; remove it only if it is in the list.

C. Show and test.

Print only the final list, then its length, on two lines. Try each test’s five replies one at a time, then check.

TestThree titlesNew firstRemoveFinal count
1Glow, Orbit, HomeSparkOrbit2
2Rain, Cloud, SunMoonStar3
Stuck?

Use Tasks 4 and 6. Build and test one part at a time.

Coding task8 marks
# Create the empty list.

# Repeat input and append three times.

# After the loop: replace the first title using input.

# Take input for a title to remove; check before removing.

# Print the final list and its length.

Task 9: Save a loop reminder

Copy a three-repeat loop into your book. Label the for line, code inside, and code after the loop. Add: “Create the list before the loop.”

This book note has no platform marks.