0
0
Pythonprogramming~15 mins

Math-related operations in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Math-related operations
📖 Scenario: You are helping a small shop owner calculate the total cost of items bought by customers. Each item has a price, and the owner wants to know the total amount to charge.
🎯 Goal: Build a simple Python program that stores item prices, sets a discount threshold, calculates the total price of items above the threshold, and prints the final total.
📋 What You'll Learn
Create a dictionary with item names and their prices
Create a discount threshold variable
Calculate the sum of prices for items with prices above the threshold
Print the total sum
💡 Why This Matters
🌍 Real World
Shop owners and cashiers often need to calculate totals and apply discounts based on price thresholds.
💼 Career
Understanding how to work with data collections and conditions is essential for roles in data entry, retail software, and basic programming tasks.
Progress0 / 4 steps
1
Create the item prices dictionary
Create a dictionary called items with these exact entries: 'apple': 30, 'banana': 10, 'orange': 20, 'mango': 50
Python
Need a hint?

Use curly braces {} to create a dictionary with key-value pairs.

2
Set the discount threshold
Create a variable called threshold and set it to 20
Python
Need a hint?

Just assign the number 20 to the variable named threshold.

3
Calculate total price above threshold
Create a variable called total and use a for loop with variables item and price to iterate over items.items(). Add price to total only if price is greater than threshold
Python
Need a hint?

Start total at 0. Use a for loop to check each price. Add price to total only if it is greater than threshold.

4
Print the total price
Write a print statement to display the value of total
Python
Need a hint?

Use print(total) to show the final sum.