0
0
Pythonprogramming~15 mins

Comparison operators in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Comparison Operators in Python
📖 Scenario: You are helping a store manager check if products meet certain price conditions to decide discounts.
🎯 Goal: Build a small program that compares product prices to a threshold and shows if they are expensive or affordable.
📋 What You'll Learn
Create a dictionary with product names and their prices
Create a price threshold variable
Use comparison operators to check if each product price is greater than the threshold
Print the product name and whether it is 'Expensive' or 'Affordable'
💡 Why This Matters
🌍 Real World
Stores often need to compare prices to decide discounts or promotions.
💼 Career
Understanding comparison operators is essential for data filtering and decision-making in programming jobs.
Progress0 / 4 steps
1
Create the product prices dictionary
Create a dictionary called products with these exact entries: 'Laptop': 1200, 'Smartphone': 800, 'Tablet': 400, 'Headphones': 150
Python
Need a hint?

Use curly braces {} to create a dictionary with keys and values separated by colons.

2
Set the price threshold
Create a variable called price_threshold and set it to 500
Python
Need a hint?

Just assign the number 500 to the variable price_threshold.

3
Compare prices using comparison operators
Use a for loop with variables product and price to iterate over products.items(). Inside the loop, create a variable called status that is 'Expensive' if price > price_threshold, otherwise 'Affordable'
Python
Need a hint?

Use a for loop to go through each product and its price. Use an if-else expression to set status.

4
Print the product status
Inside the for loop, write a print statement that shows the product name and its status in this format: "Laptop is Expensive"
Python
Need a hint?

Use an f-string to combine product and status in the print statement.