🎯 Learning Objectives
- Use iteration (while statements) to control the flow of program execution
- Perform operations on lists or individual items
- Perform operations on strings or individual characters
💬 Key Vocabulary
- Iteration
- Boolean/logical expression (condition)
- list operations (append, insert, pop, remove, index, count, reverse, sort, length)
- list
- list membership
- index
- list item
📖 Form a band
This program reads the name of an instrument and adds it to a list.
This action needs to be performed repeatedly, in order to add all the instruments required to form a band.

We could just copy and paste the same bit of code lots of times.
This approach won’t get us far.
How can we get our programs to perform actions repeatedly?

📖 Iteration recap
You need an iterative structure. (while) when your program needs to repeat actions, while a condition is satisfied.

Let’s modify this program together to use iteration (a while-loop), in order to repeat the same actions.
Follow along with your teacher to complete the code below by copying it into Thonny.

print("Let's form a band")
band = []
print("Pick an instrument:")
instrument = input()
band.append(instrument)
print(band)
📝 Level 1 – City Hopping
Complete the tasks using the worksheet you can download below to create a random-trip planner in the Trinket window also below. Do not use Thonny.
📖 Strings (are a lot like lists)
The built-in len function returns the length (number of items) of a list.
Syntax: len
(list)

The len function returns the length (number of characters) of a string.
Syntax: len
(string)

The in operator checks if a value is equal to any item in a list.
Expressions formed with in evaluate to either True or False.
Syntax: item in
list

The in operator checks if a string is contained within another string.
Expressions formed with in evaluate to either True or False.
Syntax: string in
string

An item in a list can be accessed through its index.
Syntax: list[index]

A character in a string can be accessed through its index.
Syntax: string[index]

📝 Level 2/3 – City Guessing
- Start with a program that uses the familiar list of European cities and complete the task on your worksheet to extend it into a city guessing game with hints.
- As before use the Trinket below to complete your code.
💬 Summary
In this lesson, you…
- Used iteration (while statements) to control the flow of program execution
- Practised using common operations on lists
- Performed operations on strings
Next lesson, you will…
- Use iteration (for statements) to iterate over list items
- Practise using common operations lists and strings
🏅 Level Up
🥇 Level 1
- Upload your completed Level 1 – City Hopping worksheet to the assignment on Teams.
🥈 Level 2
- Upload your completed Level 2/3 – City Guessing worksheet to the assignment on Teams.
🥉 Level 3
- Upload your completed Level 2/3 – City Guessing worksheet to the assignment on Teams as well as the Explorer task.