0
0
Pythonprogramming~15 mins

Basic list comprehension syntax in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Basic List Comprehension Syntax
๐Ÿ“– Scenario: You work in a small bakery that keeps track of daily sales in a list. You want to quickly create a new list showing the prices with tax added.
๐ŸŽฏ Goal: Build a Python program that uses list comprehension to add tax to each price in a list.
๐Ÿ“‹ What You'll Learn
Create a list of prices
Create a tax rate variable
Use list comprehension to add tax to each price
Print the new list with prices including tax
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Adding tax or fees to prices is common in stores and online shops.
๐Ÿ’ผ Career
Understanding list comprehension helps you write clean, fast code for data processing tasks.
Progress0 / 4 steps
1
Create the list of prices
Create a list called prices with these exact values: 2.5, 3.0, 4.75, 1.25, 5.0
Python
Need a hint?

Use square brackets and separate numbers with commas.

2
Create the tax rate variable
Create a variable called tax_rate and set it to 0.08 (which means 8% tax).
Python
Need a hint?

Just assign 0.08 to tax_rate.

3
Use list comprehension to add tax
Create a new list called prices_with_tax using list comprehension. For each price in prices, calculate price * (1 + tax_rate).
Python
Need a hint?

Use the syntax: [expression for item in list]

4
Print the new list
Write a print statement to display the prices_with_tax list.
Python
Need a hint?

Use print(prices_with_tax) to show the list.