So far, we have learned
- How to create a list
- How to create a list of lists using
zip
- How to add elements to a list using either
.append()
or+
- How to use
range
to create lists of integers
Let’s practice these skills.
Instructions
Maria is entering customer data for her web design business. You’re going to help her organize her data.
Start by turning this list of customer first names into a list called first_names
. Make sure to enter the names in this order:
- Ainsley
- Ben
- Chani
- Depak
Create an empty list called age
.
Depak’s age is 42
. Use .append()
to add 42
to age
.
Maria needs a list of the ages for all customers. Create a new list called all_ages
that adds age
with the following list, containing the ages for Ainsley, Ben, and Chani:
[32, 41, 29]
Make sure all_ages
begins with the ages for Ainsley, Ben, and Chani and ends with Depak’s age (stored in age
)!
Create a new variable called name_and_age
that combines first_names
and all_ages
using zip
.
Create a range object called ids
with an id number for each customer. Since there are 4 customers, so id values should go from 0
to 3
.