Skip to main content

Section 3.1 Lists

135 minutes
We use lists every day to keep track of things, for example, shopping lists, to-do lists, or song playlists. Python makes it easy to work with lists. In this topic, we will learn to use lists to store values, manipulate list contents, and traverse lists with loops.

Subsection 3.1.1 Lists as Data Collections

Essential Knowledge 3.1.1 3.1.A.1.

A data collection is a way to store multiple related values together so a program can treat them as one unit, such as storing multiple names, scores, or messages. Different programming languages support different kinds of collections, such as lists, arrays, or dictionaries.

Essential Knowledge 3.1.2 3.1.A.2.

Data collections help programs support user-facing features that involve many items, such as a list of saved favorites, recent searches, or a playlist. Storing related values in one variable makes it easier to manage, update, and process the information as users interact with an app.
All programming languages have ways to store collections of data. Python has a built-in data type called a list which can store an ordered sequence of items. Lists are sometimes called arrays in other programming languages.
You can imagine a list as a row of lockers where each locker holds one item or element. The lockers are numbered with an index that starts at 0 for the first locker, 1 for the second locker, and so on.

Essential Knowledge 3.1.3 3.1.A.3.

A value stored inside a data collection is an element. Programs can work with the entire collection of items as one unit or with individual elements.

Essential Knowledge 3.1.4 3.1.A.4.

In a list, elements are stored in an ordered sequence, meaning the position of each element matters (first, second, third, etc.). When the following code runs, a list called aList contains the elements v1, v2, v3, and so on.
aList = [v1, v2, v3, ...]
Here are some examples of lists in Python. Notice how square brackets [] are used to collect multiple values to store in one list variable. Instead of using many variables like score1, score2, etc., which would get unmanageable pretty quickly, you can use a single list variable like scores or shopping_list to store a collection of values.
# A shopping list
shopping_list = ["milk", "eggs", "bread", "butter"]
# A list of scores
scores = [95, 87, 92, 100]

Subsection 3.1.2 Index to Access Elements

Essential Knowledge 3.1.5 3.1.A.7.

An index is a number used to reference a specific element by position in a list or in a string. Many programming languages use zero-based indexing, meaning the first element is at index 0, the second at index 1, and so on.
To access elements in a list, we use the list name and the index (the position or number) of the element in square brackets. For example, shopping_list[0] accesses the first element in the shopping_list, which is "milk". Most programming languages, including Python, use zero-based indexing where the first item in the list is at index 0. Just like binary code, computers almost always start counting at 0.
Note that the AP CSP exam currently starts indexing at 1 in its pseudocode including in the 2027 exam, but will switch to zero-based indexing as of 2028.

Essential Knowledge 3.1.6 3.1.A.8.

Programs can access a specific list element using its index. This allows programs to read or use stored values in a list. When the following code runs, the element in aList at index j is accessed.
aList[j]
Imagine a Python list called lockers. Let’s put your books in locker 0 and a backpack in locker 1 with the code below. To get to a specific locker or a specific element in a list, use the list name followed by square brackets and the index (number) of the element you want to access like below.
lockers[0] = "books"
lockers[1] = "backpack"
print("What's in locker 0?", lockers[0] )
print("What's in locker 1?", lockers[1] )
Let’s try it below:

Activity 3.1.1.

Using the lockers list below, print what is in the first and last locker using the list name and the index in square brackets, for example: lockers[0].

Subsection 3.1.3 Unplugged Activity: List of Chairs

Project 3.1.2 Unplugged List of Chairs.

In groups or as a class or individually, simulate a list using students in chairs. Organize a line of empty chairs as the list in memory. Each student who sits in a chair represents a value in the list. The first chair in the line of chairs has the index 0. The second chair has the index 1, and so on. Have students follow the code similar to the example below. Substitute in the names of students in your class. For example, chairs[0] = "Pat" means that the student in chair 0 gets up and Pat sits down. If Pat was already in a chair, they would have to get up; in real Python, assignment copies values, but in this simulation, we can’t make copies of students, so we have to simplify by emptying chairs.
# Fill the chairs with students
chairs = ["Alex", "Sam", "Ryan"]
# Students should yell out their names!
print(chairs[1])
print(chairs[0])
print(chairs[2])
# Alex gets up, Pat sits down in chair 0!
chairs[0] = "Pat"   
chairs[1] = "Riley"
chairs[2] = "Alex"
How many chairs did you use in your list? What was the index of the first and last chairs in your class? What would happen if you tried to access a chair that was larger than the last index in your list? Write your own code to swap students in chairs and print them out in a different order. Try it out with your classmates!

Activity 3.1.3.

Which code below accesses "Alex" using the following list: chairs = ["Alex", "Sam", "Ryan"]
  • chairs[0]
  • Yes, this would access "Alex". Remember that the first element in an array starts at index 0.
  • chairs[1]
  • No, this would access "Sam". Remember that the first element in an array starts at index 0.
  • chairs[2]
  • No, this would access "Ryan". Remember that the first element in an array starts at index 0.
  • chairs[3]
  • No, this would result in an IndexOutOfBounds error. Remember that the first element in an array starts at index 0.

Activity 3.1.4.

Which code below accesses "Ryan" in the array: chairs = ["Alex", "Sam", "Ryan"]
  • chairs[0]
  • No, this would access "Alex". Remember that the first element in an array starts at index 0.
  • chairs[1]
  • No, this would access "Sam". Remember that the first element in an array starts at index 0.
  • chairs[2]
  • Yes, this would access "Ryan". If there are n elements and you start indexing at 0, the last element is at index n-1.
  • chairs[3]
  • No, this would result in an IndexOutOfBounds error. Remember that the first element in an array starts at index 0.

Subsection 3.1.4 Changing List Elements with Assignment

Essential Knowledge 3.1.7 3.1.B.2.

Elements in a list can be changed to different values, which allows a program to update stored information without rebuilding the entire list. When the following code runs, the value of x is assigned to the element at index j in aList. The previous value at that index is overwritten, and the length of the list does not change.
aList[j] = x
Assignment (=) can be used to change the value of an element in a list. You can use an indexed list variable like myList[index] = value on the left side of the assignment operator just like a regular variable. For example, the code below changes the value in scores[0] to 100 using assignment:
# A list of scores
scores = [95, 87, 92, 100]
# Change the first score to 100
scores[0] = 100

Activity 3.1.5.

Change the fruits list below by changing apple to mango using assignment.
Click on next in the following Code Lens to see how the list is created in memory and then changed with assignment statements.

Activity 3.1.6.

Click on the Next button at the bottom of the code to see how the values in the list change as you step through the running program. You can see interactive tracing in any Active Code exercise by clicking the Code Lens button.

Activity 3.1.7.

What is printed by the following statements? See the Code Lens above.
numbers = [1,2]
numbers[0] = 2
numbers[1] = numbers[0] + 2
print(numbers)
  • [1, 2]
  • No, the list is changed.
  • [2, 4, 1, 2]
  • No, assignment changes the values. It does not append to the list.
  • [2, 4]
  • Yes, see how each line is calculated in the Code Lens above.
  • [2, 3]
  • No, the 0th element is 2 when the third line is executed.

Activity 3.1.8.

What would the following code print?
values = [3, 2, 1]
values[0] = values[1]
values[2] = values[2] + 1
print(values)
  • [3, 2, 1]
  • That is the original contents of values, but the contents are changed.
  • [2, 0, 2]
  • No, when you set values[0] to values[1] it makes a copy of the value and doesn’t zero it out.
  • [2, 2, 2]
  • Yes, the value at index 0 is set to a copy of the value at index 1 and the value at index 2 is incremented.
  • [2, 3, 1]
  • No, the element at index 2 is the last element in the list since we start counting at 0.

Essential Knowledge 3.1.8 3.1.B.1.

Programmers sometimes make a copy of a list so they can modify the copy, such as removing or reordering elements, while keeping the original list unchanged. Preserving the original list can make a program easier to understand, test, and debug because the program can still refer back to the original data if needed. When the following code runs, a copy of the list bList is assigned to the list aList.
aList = bList
Before making changes to a list, programmers sometimes make a copy of it first using assignment. Then the original list can be preserved and used later if needed.
# A list of scores
scores = [95, 87, 92, 100]
# Make a copy of the scores list
scores_bonus = scores
# Add bonus points to the first two scores in the copy
scores_bonus[0] += 5
scores_bonus[1] += 5

Subsection 3.1.5 Append and Length of List

Essential Knowledge 3.1.9 3.1.A.5.

Lists can start empty, which allows a program to collect information, such as items a user adds, results found during a search, or responses entered in a form. When the following code runs, an empty list is assigned to aList.
aList = [ ]
If you do not know what values you want to store in a list when you create it, you can start with empty list ([]) which is a list that contains no elements and add in elements while the program is running. For example, we can start with an empty shopping list.
# An empty shopping list
shopping_list = []

Essential Knowledge 3.1.10 3.1.A.6.

Lists can be built over time by adding new elements, often as the user enters information or the program collects it. When the following code runs, value is added to the end of aList and the length of aList is increased by 1.
aList.append(value)
Elements can be added to a list using the append function which adds the element to the end of the list.
# An empty shopping list
shopping_list = []
shopping_list.append("milk")
shopping_list.append("eggs")
shopping_list.append("bread")
print(shopping_list)

Essential Knowledge 3.1.11 3.1.B.3.

The length of a list can change while a program runs as elements are added or removed. Knowing the length of a list helps programmers write code that works correctly as the list changes. When the following code runs, it evaluates to the number of items in aList.
length(aList)
In Python, you can get the length of a list by using the len(aList) function, note the shortened form of len for length. In AP Pseudocode, the function used is length(aList).
# A list of names
names = ["Jordan", "Alex", "Sam", "Taylor"]
# Get the length of the names list
print("The length of the names list is:", len(names))
The length of the list will increase as elements are added. Let’s try append and len below.

Activity 3.1.9.

Add two more items to the shopping_list below. Then, print the list and the length of the list.

Essential Knowledge 3.1.12 3.1.A.9.

Lists support apps that respond to users by remembering and reusing information. For example, a music app can store a user’s queued songs in a list. Each time the user taps "Add to Queue," the song title is appended to the list, and the app uses the list to display the upcoming songs in order and play the next track.

Subsection 3.1.6 Insert and Remove List Elements

Essential Knowledge 3.1.13 3.1.B.4.

Elements can be inserted at particular positions in a list, which allows a program to keep items in a meaningful order, such as priority or ranking, as new information is added. When the following code runs, any elements at indices greater than or equal to j are shifted so that their indices are increased by 1 and value is placed at index j. The length of the list is increased by 1.
aList.insert(j, value)

Essential Knowledge 3.1.14 3.1.B.5.

Elements at particular positions can be removed from a list, which allows a program to delete outdated, incorrect, or unwanted information while keeping the remaining elements usable. When the following code runs, the element at index j is removed and the elements after it shift one position so that their indices are decreased by 1. The length of the list is decreased by 1.
aList.remove(j)
Python also provides built-in functions to change list elements. We already saw the append() function, which adds an element to the end of a list. We can also use list.insert(index, element) that adds an element at a specific index and moves the elements after it one position to the right. It’s important to remember that append, insert, and remove always change the length of the list moving elements to the right or left as needed!
In the AP CSP Pseudocode, the functions to change a list are similar to those in Python, but the AP CSP pseudocode list.remove(index) function removes the element from the list at a certain index. Python has list.remove(value) which deletes the very first occurrence of a specific value from the list or list.pop(index) which removes and returns the element at a specific index, but not a list.remove(index) function.

Activity 3.1.10.

The code below uses a list to keep track of dogs at the animal shelter. Try the insert and remove functions in the code below. Then follow the directions in the comments to insert and remove elements from the list.

Subsection 3.1.7 Tracing List Operations and Index Errors

Project 3.1.11 Unplugged List of Chairs Revisited.

Let’s revisit the unplugged activity with students in chairs and simulate append, insert, and remove operations. In groups or as a class or individually, organize a line of empty chairs as the list. Have some extra chairs ready to append or insert. Each student who sits in a chair represents an element in the list. The first chair in the line has the index 0. The second chair has the index 1, and so on. Have students follow the code below to insert and remove students and chairs. Substitute in the names of students in your class.
# Fill the chairs with students
chairs = ["Alex", "Sam", "Ryan"]
# Example code to insert and remove students in chairs
chairs.append("Dani") # Add a new chair and student to the end of the list
# Remove the student in chair 1, move students left 1 chair, 
#   and remove the last chair
chairs.remove(1) 
# Insert a new student in chair 1 and move students to the right to make room.
chairs.insert(1, "Taylor")
How do append, insert, and remove affect the list differently than changing the values of existing elements? Write your own code below using append, insert, and remove, and then act it out.

Essential Knowledge 3.1.15 3.1.B.7.

Apps often update lists in response to user actions. Adding or removing items supports user goals such as saving favorites, managing a to-do list, updating a roster, or keeping a recent-search history. Programmers choose list operations that match how users expect information to change as they interact with the app.

Essential Knowledge 3.1.16 3.1.B.8.

To determine what output a program produces after list operations, programmers trace statements in order and update the list after each step. This includes tracking how element positions change when items are inserted or removed and using the updated list to determine what values are accessed or displayed next.

Activity 3.1.12.

What are the values in the list after executing the following AP Pseudocode? Remember that list indexing starts at 0 and the pseudocode uses list.insert(index, value) and list.remove(index) to change the list. Insert and remove always change the length of the list moving elements to the right or left as needed. To trace this code, write down the list after each line of code.
list = [ 0, 3, 5 ]
list.append(7)
list.insert(0, 1)
list.remove(1)
  • [1, 3, 5, 7]
  • Yes, the list is updated as follows: [0, 3, 5], after appends [0, 3, 5, 7], then insert [1, 0, 3, 5, 7], then remove [1, 3, 5, 7].
  • [0, 1, 3, 5, 7]
  • Don’t forget the remove!
  • [0, 3, 5, 7]
  • No, this is correct after the append, but not after the insert.
  • [3, 5, 7]
  • No, the insert does not replace the element but inserts and moves everything down.

Essential Knowledge 3.1.17 3.1.B.9.

List operations that use an index depend on the index being valid for the current list. When a program accesses, updates, inserts, or removes using an index, programmers must consider the current length of the list and how earlier operations may have shifted element positions. In many programming languages, using an index that is outside the allowed range produces an error and may cause the program to stop.
What happens if you try to access an element that is not there? Try to access puppies at index 7 below to see what happens. The index must be between 0 and the length of the list - 1 or it will give an error message "IndexError: list index out of range".

Activity 3.1.13.

Run the code below to see an index out of range error. Fix the error by changing the index.

Subsection 3.1.8 Random Elements and List Slicing

Essential Knowledge 3.1.18 3.1.B.6.

To select a random element from a list, a program can generate a random index and use it to access an element. This allows for features like selecting a random song from a playlist, choosing a random prompt in a game, or assigning a random partner from a list of names. In programming languages that use zero-based indexing, if aList has length(aList) items, the valid indices are 0 through length(aList) - 1. When the following code runs, the program generates one of the valid indices with equal likelihood and accesses the element at that index.
aList[random(0, length(aList) - 1)]
Sometimes you may want to pick a random element from the list. One way to do this is to generate a random index. It would start at 0 and go up to the length of the list minus 1. If there are 3 elements in the list, the valid indices would be 0, 1, and 2. In Python, you can use the random.randint() function to generate a random index. The valid indices are 0 through len(list) - 1. For example, if you have a list of songs, you can select a random song from the playlist using the code random.randint(0, len(songs) - 1). Python actually has a built-in function called random.choice(list) that will select a random element from a list, but we will use the random index method here to match AP pseudocode.
import random
songs = ["Song 1", "Song 2", "Song 3", "Song 4"]
random_index = random.randint(0, len(songs) - 1)
random_song = songs[random_index]
print(random_song)

Activity 3.1.14.

Use the code below to select a random emoji from the list. Use the random.randint() function to generate a random index and then use that index to access an element in the list. Run the code multiple times to see different emojis printed!
Python also has a cool slicing operator ([start:end]) that allows you to extract a portion of a list from a start index up to (but not including) an end index, just like we saw with strings.

Activity 3.1.15.

Write code that prints out slices of the emoji list, using [start-index : up-to-end-index].

Subsection 3.1.9 Traversing Lists with Loops

Essential Knowledge 3.1.19 3.1.C.3.

Iteration statements can be used to traverse a list, which allows a program to process each element in order without writing repeated code for every element. When the following code runs, the variable item is assigned the value of each element of aList sequentially, in order, from the first element to the last element. The code in block of statements is executed once for each element in aList.
for item in aList
{
   <block of statements>
}
Python has a simple way to traverse (step through) a list, visiting each element in the list, using a for loop with the pattern: for item in list:
aList = [1, 2, 3, 4, 5]
for item in aList:
    print(item)

Activity 3.1.16.

Write code that uses a for loop to print out each emoji in the list on a separate line.
An index-controlled for-loop using range(len(aList)) or a while loop can also be used to traverse a list. The loop variable is the index to access each element in the list. This is why programmers often use the variable i, short for index, as the loop variable. However, it is a lot more complex. If you do not need the index, it is simpler to use the for item in list loop instead. The code below compares all three loops. The first one is the simplest and most often used with lists.
aList = [1, 2, 3, 4, 5]
# Simple for loop for lists
for item in aList:
    print(item)

# More complex indexed for-loop
for i in range(len(aList)):
    print( aList[i] )

# More complex while loop
i = 0
while i < len(aList):
    print( aList[i] )
    i += 1

Activity 3.1.17.

Write code that uses an indexed for loop using range(0,len(list)) to print out each emoji in the list on a separate line with the index.

Subsection 3.1.10 Accumulator Pattern with Lists

Essential Knowledge 3.1.20 3.1.C.1.

Traversing a list is often used to accomplish a goal, such as counting elements that meet a condition, finding a value (like a maximum), computing a total or average, or building an output (such as a message that includes all elements that match a rule).

Essential Knowledge 3.1.21 3.1.C.2.

Traversals often update an accumulator variable, such as a count or total, each time an element is processed.
When we were learning about loops, we learned about the accumulator pattern which uses a loop and an accumulator variable to keep track of the running total as each number is added in. This accumulator pattern is often used to process lists and perform calculations on the elements.
The Accumulator Pattern or Algorithm has the following steps:
  1. Initialize the accumulator variable before the loop.
  2. Loop through the values.
  3. Update the accumulator variable inside the loop.
  4. Print or use the accumulated value when the loop is done.
For example, the count variable can be an accumulator variable to count the number of elements in a list or sum can be an accumulator variable to calculate the sum of all the elements in a list. We can compute the average of a list by dividing the sum by the length of the list using len(list).
scores = [ 100, 90, 95, 85, 93 ]
sum = 0

for number in scores:
    sum += number

Activity 3.1.18.

The following program has the correct code to return the average of a list of numbers, but the code is mixed up. Drag the blocks from the left into the correct order on the right. You will be told if any of the blocks are in the wrong order or are indented incorrectly.

Activity 3.1.19.

Count the number of elements in the list using a for loop and an accumulator variable.

Activity 3.1.20.

Use the accumulator pattern to add taxes to each price in a list of prices. Try Code Lens to see the variable values change as the program runs.

Subsection 3.1.11 Coding Challenge: Parallel Lists in a Bakery

A bakery uses parallel lists to store the names, emoji images, and prices of baked goods in three lists. The lists are kept in parallel order so that an index can be used to access the corresponding elements in each list. For example, the first element in the list of baked goods corresponds to the first element in the list of prices, the second element corresponds to the second element, and so on. This allows a program to easily look up the price and image of a baked good by index. In the following coding challenge, you will use an input-controlled while loop to ask the user to choose baked goods from the bakery and put its index in an order list. You will then print out their receipt and calculate the total cost of their order using a for loop and the order list.

Project 3.1.21 Bakery Parallel Lists.

A bakery uses 3 parallel lists below to store the names, emoji images, and prices of baked goods. The while-loop below prints the lists and asks for the user’s order by choosing an index number. You will write code to append the chosen index to the order list after checking that it is in range. You will then print out their receipt and calculate the total cost of their order using a for loop and the order list.

Subsection 3.1.13 Data Abstraction with Lists

In previous lessons, we talked about abstraction in computer science which is about focusing on the general features while hiding the specific details. Data Abstraction is the process of hiding the complex implementation details of a data structure and showing only the needed features to the user. Variables are a type of data abstraction because they allow programmers to use a name to represent a value without needing to know how the value is stored in memory. Lists are another type of data abstraction because they allow programmers to use a single variable name to represent a collection of values without needing to know how the values are stored or organized in memory. Data abstraction using lists reduces complexity in code and makes it easier to read, write, and maintain.

Essential Knowledge 3.1.26 3.1.D.1.

Data Abstraction manages complexity by allowing programmers to use data based on its name and purpose without needing to focus on how the data is represented. This separation helps programmers reason about what the data represents and what operations can be done with it.

Essential Knowledge 3.1.27 3.1.D.2.

A list is a type of data abstraction because it allows many related values to be treated as a single variable. Instead of writing code for many individual variables, programmers can use the list’s name to perform the same kinds of operations on its elements, such as accessing, updating, inserting, removing, or traversing.

Activity 3.1.28.

A programmer creates a program that displays the names of all students enrolled in a class. Which implementation best demonstrates the use of data abstraction?
  • student1 = "Alex"
    student2 = "Marion"
    student3 = "Jordan"
    
  • No. This implementation uses a separate variable for each student rather than treating the related values as a single collection.
  • students = ["Alex", "Marion", "Jordan"]
    
  • Yes. A list allows related values to be treated as a single data abstraction. The programmer can use the name students to work with the collection without needing separate variables for each student.
  • studentCount = 3
    
  • No. This variable stores the number of students but does not provide a collection containing the students’ names.
  • print("Alex")
    print("Marion")
    print("Jordan")
    
  • No. This implementation contains repeated statements instead of using a single abstraction to represent the related student names.

Essential Knowledge 3.1.28 3.1.D.3.

Using data abstractions such as lists can make programs easier to develop, read, test, and maintain because the same algorithm can often work even when the amount of data changes. When elements are added or removed, the code structure often stays the same.

Essential Knowledge 3.1.29 3.1.D.4.

Data abstraction makes it easier to adapt a program as user needs change (for example, handling more saved favorites, more songs on a playlist, or more messages) without redesigning the entire program.
Data abstraction also makes it easier to add data without having to rewrite the algorithms. Try adding data to the list below. You will see that you do not need to rewrite the loop processing the list at all. This makes it much easier to maintain and update the code.

Activity 3.1.29.

Add at least 3 more colors to the list below. Do you need to change the for-loop?

Essential Knowledge 3.1.30 3.1.D.5.

Data abstraction reduces complexity by reducing duplication in code. For example, using a single list and a loop can process any number of elements, instead of requiring many separate variables and repeated statements. This means fewer places to update code during development, which lowers the chance of errors.
Data abstraction using lists also removes a lot of repetitive duplication in code. Instead of having multiple variables and repeated code to process each variable, we can use a single list and a loop to process all the elements.
Refactoring code means to rewrite the code to improve it while maintaining the same functionality. Adding data abstraction is a great way to refactor code to reduce its complexity and make it more maintainable and easier to understand. Try it below!

Activity 3.1.30.

Refactor the following code to use a list instead of individual variables. Make sure you use a for-loop to traverse the list and print each favorite food.

Activity 3.1.31.

Consider the following code.
temperatures = [72, 75, 68, 70]
total = 0
for temperature in temperatures:
    total = total + temperature
print(total)
Which of the following are reasons why using data abstraction with a list reduces program complexity? Select two answers.
  • The same algorithm can process the data even if we add new temperatures or update or remove temperatures.
  • Yes. The loop processes each element in the list, so the same algorithm can work with different amounts of data without needing to be rewritten.
  • The list reduces the need for repeated variables and statements for processing individual temperatures.
  • Yes. Without a list, the programmer might need separate variables and repeated statements for each temperature. Using a list and loop reduces this repeated code.
  • The list automatically calculates the sum of the temperatures.
  • No. The list only stores the temperatures. The for loop and addition operation are responsible for calculating the sum.
  • The list guarantees that there are no duplicate temperatures.
  • No. A list can contain duplicate values. Preventing duplicate values is not a reason why using a list reduces program complexity.

Subsection 3.1.15 Coding Challenge: Quiz App

In this challenge, you will use parallel lists that contain data about the Computer Science Pioneers shown below. You will create a search app and a quiz app. There are 3 parts to this challenge: the search app, the quiz app, and the create your own data and app.
Data: AdaLovelace.png
Data: AlanTuring.png
Data: GraceHopper.png
Data: MaryJackson.png
The first part of this challenge is to use a search algorithm to find and display information from the lists.
The second part of the challenge is to create a quiz app about pioneers in computer science. The pioneers, facts, and images are in parallel lists where the first pioneer in the pioneers list corresponds to the first fact in the facts list and the first image in the image list, and so on for each element in the lists.

Project 3.1.33 Quiz App.

A quiz app uses 3 parallel lists to store the names of pioneers, facts about their contributions, and their images. Use for loops to print out questions from the facts list and check the user’s answers against the pioneers list.
Extra challenges: Add and print a score variable. Do research to find more CS pioneers and add them to the lists.
The final part of this challenge is to create your own data lists and use it in a quiz app. Create 2 parallel lists with at least 3 elements each about something you are interested in, for example famous athletes and their teams, singers and their albums, actors and their movies, animals and their habitats, or any other topic you are interested in. If you’d like to do images, you can copy in the import and draw function from the previous quiz app and use complete http or https links to small images on the web.

Project 3.1.34 Your Own Quiz App.

Create your own Quiz App using 2 parallel lists with at least 3 elements each about something you are interested in, for example famous athletes and their teams, singers and their albums, actors and their movies, animals and their habitats, or any other topic you are interested in. First, present some information about the topic using a search algorithm like in part 1 of this challenge. Then, create a quiz app like in part 2 of this challenge.

Activity 3.1.35 Data Abstraction Reflection.

Consider the lists used in your project code above.
  1. Explain how the lists use data abstraction to manage complexity in your program.
  2. Explain how your code would be more complex if you did not have lists.
  3. If you decide to add more elements to your lists, describe how you would need to adjust your code. How do lists make this easier?

Subsection 3.1.16 Learning Objectives Review

Learning Objective 3.1.31 3.1.A.

Develop code that stores multiple related values in a single variable.

Learning Objective 3.1.32 3.1.B.

Develop code to manipulate a list, and determine the result produced.

Learning Objective 3.1.33 3.1.C.

Develop code using iteration statements to traverse a list, and determine the result produced.

Learning Objective 3.1.34 3.1.D.

Explain how the use of data abstraction manages complexity in program code.

Subsection 3.1.17 Vocabulary Review

Activity 3.1.36.

You have attempted of activities on this page.