Project: grocery list
Python · Unit 5: Lists
- Full plan
- Python
- Project
- 3 exercises
Your grocery list is two lists: items[i] and prices[i] talk about the same product, because the same index ties them together.
With enumerate you walk one and read the other with the index.
items = ["bread", "milk"]
prices = [3, 4]
for i, p in enumerate(prices):
print(items[i], p)Prints
bread 3 milk 4
Exercises in this lesson
You do them in the app, which checks them on the spot and explains why.
1. Complete the code
Complete it to print the items that cost less than 10.
2. Write the code
Write
total(prices, counts), which returns what you pay if you takecounts[i]of each product atprices[i]each.3. Write the code
Write
priciest(items, prices), which returns the name of the most expensive product. The lists never come in empty.
Do this lesson
See all lessons →It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.