0
0
Pythonprogramming~30 mins

Logical operators in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Using Logical Operators in Python
📖 Scenario: You are helping a small store decide if a customer qualifies for a special discount based on their age and membership status.
🎯 Goal: Build a program that uses logical operators to check if a customer is either a member or an adult, and then print if they qualify for the discount.
📋 What You'll Learn
Create a dictionary with customer names as keys and their ages as values
Create a set of members containing the names of customers who are members
Use logical operators and, or, and not to check conditions
Print the qualification result for each customer
💡 Why This Matters
🌍 Real World
Stores often give discounts based on membership or age. This program helps decide who gets a discount.
💼 Career
Understanding logical operators and data structures is key for roles in software development, data analysis, and automation.
Progress0 / 4 steps
1
Create the customer data
Create a dictionary called customers with these exact entries: 'Alice': 17, 'Bob': 20, 'Charlie': 16, 'Diana': 22
Python
Need a hint?

Use curly braces {} to create the dictionary with the exact names and ages.

2
Create the members set
Create a set called members containing the exact names 'Alice' and 'Diana'
Python
Need a hint?

Use curly braces {} to create a set with the exact member names.

3
Check discount qualification using logical operators
Write a for loop using variables name and age to iterate over customers.items(). Inside the loop, create a variable qualifies that is True if the customer is either in members or their age is 18 or more, using the or operator. Use the not operator to check if the customer is not a member and under 18.
Python
Need a hint?

Use or to check if the customer is a member or adult. Use not and and to check if they are not a member and under 18.

4
Print the qualification results
Inside the for loop, write a print statement that outputs exactly: "Alice qualifies for discount: true" (replace Alice with the name variable and true with the qualifies variable) for each customer.
Python
Need a hint?

Use an f-string in the print statement to show the name and qualification status.