Formatting structured data
📖 Scenario: You work in a small shop and keep track of product prices in a dictionary. You want to show the prices neatly formatted with a dollar sign and two decimal places.
🎯 Goal: Create a dictionary of products and prices, then format the prices as strings with a dollar sign and two decimals using dictionary comprehension.
📋 What You'll Learn
Create a dictionary called
products with these exact entries: 'apple': 0.4, 'banana': 0.25, 'cherry': 0.15Create a variable called
formatted_prices using dictionary comprehension to format each price as a string with a dollar sign and two decimal placesPrint the
formatted_prices dictionary💡 Why This Matters
🌍 Real World
Formatting prices neatly is important for receipts, price tags, and online stores to make prices clear and professional.
💼 Career
Many jobs in retail, web development, and data processing require formatting and displaying structured data clearly.
Progress0 / 4 steps