Community resourceWorksheet
Y9-L04 Lists and for loops Consolidation
Part 4 of 4 · Y9 Lists
Pupils revise list creation, indexing, appending, removing items, and filtering with for loops in Python. The worksheet uses short code tasks, prediction questions, and a small build challenge to collect replies and make a shortlist. It is fairly demanding for a Year 9 class because it combines several list and loop ideas and asks pupils to fix errors as well as write code.
Shared by Mr HopkinsonVerified teacher
- 24 cells
- CC BY-SA 4.0
- Shared 25 Nov 2026
Preview
The whole resource, exactly as a class sees it. Answers and marking are held back.
Lists and for loops
Use lists to store and change items. Use loops to collect replies and make a shortlist.
Quick recap
Use square brackets, commas between items and quotes around text.
Each row below starts with this list.
activities = ["Art", "Quiz", "Film"]
| Code | Job |
|---|---|
activities[0] | Access the first item. Indexes start at 0. |
activities[0] = "Music" | Replace the first item. |
activities.append("Games") | Add one item at the end. |
activities.remove("Quiz") | Remove the first matching value. |
activities.pop(1) | Remove the item at index 1. |
len(activities) | Count the items. Here the length is 3. |
Check that a value is present before using remove().
if "Quiz" in activities:
activities.remove("Quiz")
Two useful loops
Repeat three times
activities = []
for turn in range(3):
activity = input("Activity? ")
activities.append(activity)
Visit each item and check it
activities = ["Art", "Quiz", "Film"]
shortlist = []
for activity in activities:
if activity != "Quiz":
shortlist.append(activity)
print(shortlist)
activity holds the current item. activities is the whole list.
== checks equality. != checks for different values. Text comparisons use exact spelling and capitals.
Use four spaces inside a loop and eight inside an if in that loop.
Input reminder
In input("Activity? "), the text is the question. Store the reply in a variable.
Task 1. Create and access
Fill three gaps to create the list, print its first item and print its length. Run and Check my answer. Expect Art, then 3.
activities = Gap 1"Art", "Quiz", "Film"]
print(activities[Gap 2])
print(Gap 3(activities))- 1
- (
- len
- [
- 0
Task 2. Predict a change
Read the code before choosing.
snacks = ["Grapes", "Popcorn"]
snacks[0] = "Crackers"
snacks.append("Pretzels")
print(len(snacks))
What is printed?
- A2
- B3
- C4
- DCrackers
Task 3. Change the list
Fill three gaps. Replace the first item with Dance, append Games, then remove one Quiz if present.
Run and Check my answer. Expect ['Dance', 'Film', 'Quiz', 'Games'].
activities = ["Art", "Quiz", "Film", "Quiz"]
activities[Gap 1] = "Dance"
activities.Gap 2("Games")
remove_activity = "Quiz"
if remove_activity in activities:
activities.Gap 3(remove_activity)
print(activities)- pop
- 1
- remove
- len
- 0
- append
Task 4. Fix the indexes
Remove the second item by index with pop(). Fix the final print to access the last remaining item.
Run and check. Expect Film.
Index reminder
After deletion, count indexes again from 0.
activities = ["Art", "Quiz", "Film"]
activities.pop("Quiz")
print(activities[2])Task 5. Check the repeats
The user types Art each time. Choose two true statements.
activities = []
for turn in range(3):
activity = input("Activity? ")
activities.append(activity)
remove_activity = "Quiz"
if remove_activity in activities:
activities.remove(remove_activity)
print(len(activities))
Choose two true statements.
- Ainput() runs three times.
- Bremove() runs once.
- CThe final output is 3.
- DThe missing Quiz causes an error.
Task 6. Collect three replies
Complete and fix the starter.
- Create an empty
activitieslist before the loop. - Fix the loop to repeat three times.
- Use
input()to save each reply inactivity. - Append each reply inside the loop.
Run with Art, Quiz, Film, one at a time. Expect a list containing all three. Check my answer.
Store the reply
Use input("Activity? ") to take input. Use activity without quotes when appending.
# Create the empty list before the loop.
for turn in range(2):
activity = print("Activity? ")
# Add each reply to the list inside the loop.
print(activities)Task 7. Find each match
Fill three gaps to print every matching item. Run and check. Expect Music on two lines.
activities = ["Music", "Art", "Music"]
wanted = "Music"
Gap 1 activity in activities:
if activity Gap 2 wanted:
print(Gap 3)- activities
- for
- !=
- activity
- if
- ==
Task 8. Predict the shortlist
Read the code before choosing.
activities = ["Art", "Quiz", "Art"]
shortlist = []
for activity in activities:
if activity != "Art":
shortlist.append(activity)
print(shortlist)
What is printed?
- A['Art', 'Quiz']
- B['Art', 'Art']
- C[]
- D['Quiz']
Task 9. Repair the filter
Fix three things.
- Create the empty shortlist before the loop.
- Keep items that differ from
skip. - Append the current item inside the
if.
Run and check. Expect ['Quiz', 'Music'].
activities = ["Art", "Quiz", "Art", "Music"]
skip = "Art"
for activity in activities:
shortlist = []
if activity == skip:
shortlist.append(activities)
print(shortlist)Task 10. Build your activity shortlist
Complete the starter in three stages.
A. Collect
Create activities = [] before a for loop. Use range(3) to take and append three replies.
B. Choose
Take input for an activity to skip. Create shortlist = []. Loop through activities. Use if and != to append each item that differs from the reply. Keep activities unchanged.
C. Show and test
Print the shortlist, then its length on the next line. Try both rows, one reply at a time, then check.
| Three activity replies | Reply to skip | Final length |
|---|---|---|
| Art, Quiz, Art | Art | 1 |
| Dance, Music, Film | Games | 3 |
Build one part at a time
Use Tasks 6 and 9. Collect three replies first, then add the filtering loop and final prints.
# Create an empty list. Collect three activity replies.
# Take input for an activity to skip.
# Create and build the shortlist using a loop and if.
# Print the shortlist and its length.