Year 9 Lesson 2 Playlist
Year 9 Lesson 2 Playlist
1
planets = ["Mercury", "Venus", planets When the program
2
"Earth", "Mars", 0 "Mercury" is executed, this is
3
4 "Jupiter", "Saturn", 1 "Venus" what the list of
5 "Uranus", "Neptune"] 2 "Earth" planets will look
6 3 "Mars" like in memory.
position = 3
7
object = planets[position] 4 "Jupiter"
5 "Saturn" Item numbering in
3
print(object) lists begins with 0.
6 "Uranus"
7 "Neptune"
Starter activity
Walkthrough: Answer
1
planets = ["Mercury", "Venus", Question .
2
3
"Earth", "Mars", What will be displayed on the screen,
4 "Jupiter", "Saturn", when this program is executed?
5 "Uranus", "Neptune"]
6 A. Venus
position = 3 B. Earth
7
object = planets[position] C. Mars
print(object) ▹ D. Jupiter
Outcomes
In this lesson, you will...
● Perform operations on lists
● Brush up on your Python skills (mainly selection)
Activity 1
The index of an item
1
planets = ["Mercury", "Venus", Question .
2
3
"Earth", "Mars", What do you think will be displayed
4 "Jupiter", "Saturn", on the screen when this program is
5 "Uranus", "Neptune"] executed?
6
position = planets.index("Venus")
print(position)
Activity 1
The index of an item
1
planets = ["Mercury", "Venus", planets When the
2
3
"Earth", "Mars", 0 "Mercury" program is
4 "Jupiter", "Saturn", 1 "Venus" executed, this is
5 "Uranus", "Neptune"] 2 "Earth" what the list of
6
position = planets.index("Venus") 3 "Mars" planets will look
print(position) 4 "Jupiter" like in memory.
5 "Saturn" Item numbering
6 "Uranus" in lists begins
7 "Neptune" with 0.
Activity 1
The index of an item
1
planets = ["Mercury", "Venus", Question .
2
3
"Earth", "Mars", What do you think will be displayed
4 "Jupiter", "Saturn", on the screen when this program is
5 "Uranus", "Neptune"] executed?
6
position = planets.index("Venus") Answer The number 1 will be
print(position) displayed.
This is the index of the value "Venus"
in the list of planets.
Activity 1
Operations on lists
There are many operations you can
perform on lists and their items. Some examples
list.append(item) add item at end of list numbers.append(42)
list.insert(index, item) add item at index cities.insert(2, "Oslo")
list.pop(index) remove item at index last = values.pop()
list.remove(item) remove item countries.remove("Japan")
list.index(item) search for index of item where = planets.index("Mars")
list.count(item) get occurrences of item nb_the = words.count("the")
list.reverse() reverse list values.reverse()
list.sort() sort list names.sort()
Activity 2
Driver
Control the keyboard and mouse
Navigator
Provide support and instructions
1 dwarves = Create the list of dwarf planets In 2006, some sub-planetary objects
were classified as dwarf planets.
4
print("Dwarf planets:")
5 Challenge .
print(dwarves)
Create a list containing names of
dwarf planets: Ceres, Ataecina, Eris,
and Makemake.
Activity 2
The solar system: Solutions
1
dwarves = ["Ceres", "Ataecina", In 2006, some sub-planetary objects
"Eris", "Makemake"] were classified as dwarf planets.
4
5 print("Dwarf planets:")
Challenge .
print(dwarves)
Create a list containing names of
dwarf planets: Ceres, Ataecina, Eris,
and Makemake.
Activity 2
The solar system: Solutions
1
dwarves = ["Ceres", "Ataecina", In 2008, Haumea was recognised as
"Eris", "Makemake"] the official name of Ataecina.
2
Change second list item to Haumea
4 Challenge .
5 print("Dwarf planets:")
Continue with your existing program.
print(dwarves)
Modify the second item of the list.
Sort Each player’s rolls are sorted in descending order (highest first).