Computer 2

Monday, March 2, 2026

Python Lists Review

Agenda

  1. Finish the Inventory Manager Project and turn it in. Save your code as lastname_inventory.py and copy it to your OneDrive folder. It is due at the end of class today.
  2. Use the rest of class to study for the Python lists quiz on Thursday, March 5, 2026. Use the review questions below to check your understanding. Also study using your worksheet with these answers.
  3. If you finish the review questions and have time left over, try the mini project at the end of this page! It is not required, but it will give you extra practice with lists.


Python Lists Review

For each question below, think about the answer before clicking "Reveal Answer". If you get it wrong, make sure you understand why before moving on.

Creating and Accessing Lists

# 1

Write one line of code to create a list called knights that contains the names "Arthur", "Lancelot", and "Galahad".

knights = ["Arthur", "Lancelot", "Galahad"]

# 2

Given knights = ["Arthur", "Lancelot", "Galahad"], what does print(knights[0]) print?

Arthur

# 3

Given knights = ["Arthur", "Lancelot", "Galahad"], what does print(knights[-1]) print?

Galahad — Using -1 always gives you the last item in the list.

# 4

Given knights = ["Arthur", "Lancelot", "Galahad"], what does print(len(knights)) print?

3

Modifying Lists

# 5

Given knights = ["Arthur", "Lancelot", "Galahad"], write one line of code to add "Percival" to the end of the list.

knights.append("Percival")

# 6

Given knights = ["Arthur", "Lancelot", "Galahad"], write one line of code to replace "Lancelot" (at index 1) with "Gawain".

knights[1] = "Gawain"

# 7

Given knights = ["Arthur", "Lancelot", "Galahad"], write one line of code to remove "Lancelot" from the list.

knights.remove("Lancelot")

# 8

What does knights.pop() do (with no argument)?

It removes and returns the last item in the list.

Looping and Searching

# 9

Given scores = [95, 82, 74, 100, 68], write a for loop that prints each score on its own line.

for score in scores:
    print(score)

# 10

Given inventory = ["sword", "shield", "potion"], write an if statement that prints "You have a potion!" if "potion" is in the list.

if "potion" in inventory:
    print("You have a potion!")

# 11

Given scores = [95, 82, 74, 100, 68], write code to print the total number of scores in the list.

print(len(scores))

# 12

Given names = ["Charlie", "Alice", "Bob"], write one line of code to sort the list alphabetically.

names.sort() — After this, names will be ["Alice", "Bob", "Charlie"].



Mini Project: High Score Tracker

If you have finished the Inventory Manager Project and have finished the review questions, try this challenge for additional practice.

Write a program called High Score Tracker that lets a user manage a leaderboard for their favorite game. The program should:

  1. Start with a list of three player names and a matching list of three scores (you pick them).
  2. Display a menu with the following options:
  3. Keep looping until the user chooses Quit.

Here is an example of how the program might look:

== HIGH SCORE TRACKER ==
1. Show leaderboard
2. Add player
3. Show highest score
4. Show number of players
5. Quit

Choose an option: 1

Leaderboard:
 Marcus - 4500
 Jake - 3200
 Deon - 5100

Choose an option: 3
Highest score: 5100

Choose an option: 2
Player name: Tyler
Score: 4800
Tyler added!

Choose an option: 5
Goodbye!

Hint: Use the built-in max() function to find the highest score in your scores list — for example, max(scores).

Save your program as lastname_highscores.py and copy it to your OneDrive folder if you finish it.