Comparison operators
📖 Scenario: You are working in a store that sells fruits. You want to check which fruits have prices less than or equal to a certain budget.
🎯 Goal: Create a MATLAB script that uses comparison operators to find which fruits are affordable within a given budget.
📋 What You'll Learn
Create a dictionary (containers.Map) called
fruitPrices with exact entries: 'apple' = 3, 'banana' = 1, 'cherry' = 5, 'date' = 2Create a variable called
budget and set it to 3Use a
for loop with variables fruit and price to iterate over fruitPrices.keys and check prices using comparison operatorsCreate a logical array called
affordable that stores true for fruits with price less than or equal to budgetPrint the names of fruits that are affordable using
disp💡 Why This Matters
🌍 Real World
Stores and shops often need to filter products based on price limits to help customers find affordable options.
💼 Career
Understanding comparison operators and data structures like dictionaries is essential for data filtering and decision-making in programming jobs.
Progress0 / 4 steps