0
0
Pythonprogramming~15 mins

map() function in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Using the map() function in Python
๐Ÿ“– Scenario: You work at a fruit store and have a list of fruit prices in dollars. You want to quickly calculate the prices in cents to help with a new pricing system.
๐ŸŽฏ Goal: Learn how to use the map() function to apply a calculation to each item in a list.
๐Ÿ“‹ What You'll Learn
Create a list of fruit prices in dollars
Create a function to convert dollars to cents
Use the map() function with the conversion function and the list
Print the resulting list of prices in cents
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Stores and shops often need to convert prices between units like dollars and cents for calculations and display.
๐Ÿ’ผ Career
Understanding map() helps automate repetitive tasks on lists, which is common in data processing and software development.
Progress0 / 4 steps
1
Create the list of fruit prices in dollars
Create a list called prices_dollars with these exact values: 0.5, 1.2, 0.75, 2.0, 1.5
Python
Need a hint?

Use square brackets [] to create a list and separate values with commas.

2
Create a function to convert dollars to cents
Define a function called dollars_to_cents that takes one parameter price and returns price * 100
Python
Need a hint?

Use def to define the function and multiply the input by 100.

3
Use map() to convert all prices to cents
Create a variable called prices_cents that uses map() with the function dollars_to_cents and the list prices_dollars. Convert the result to a list.
Python
Need a hint?

Use list(map(function, list)) to apply the function to each item and get a list back.

4
Print the list of prices in cents
Write a print() statement to display the variable prices_cents
Python
Need a hint?

Use print(prices_cents) to show the final list.