Operators
Operators are special symbols and keywords that help perform an operation or computation on one or more values or variables.
The values or variables that the operator works on are called operands.
Operators are special symbols and keywords that help perform an operation or computation on one or more values or variables.
The values or variables that the operator works on are called operands.
Logical operators are used to combine multiple conditional statements or boolean expressions. They evaluate operands and return a boolean result (True or False), allowing your programs to make decisions based on more than one condition at a time.
Python has three core logical operators: and, or, and not.
Assuming x = 5 and y = 10:
Truth tables show every possible combination of inputs and what the final result will be.
You are deciding whether to order food online.
You should order food only when all of the following are true:
You are hungry.
You have enough money to pay for the food.
You are too tired to cook.
You don't already have food at home.
Write a Python program that asks the user these questions and uses logical operators to determine:“Should I order food?”
The program should display either True or False.
Sample Output:
Are you hungry? (1 = Yes, 0 = No): 1
How much money do you have? ₹500
How much does the food cost? ₹300
Are you too tired to cook? (1 = Yes, 0 = No): 1
Do you already have food at home? (1 = Yes, 0 = No): 0
Should I order food? True
An online food delivery website offers free delivery when all three conditions are satisfied:
The order amount is ₹199 or more
The delivery distance is less than 10 km
The customer is a premium member
Write a Python program that checks whether the customer gets free delivery.
Sample Output:
🍔 ONLINE FOOD ORDER
--------------------
Enter order amount: ₹350
Are you a premium member? (1 = Yes, 0 = No): 1
Enter delivery distance: 6
Do you get free delivery? True
You are going on a trip.
You need to make sure you have:
Your phone charger
Your wallet
Your ID
But if you are travelling internationally, you also need your passport.
Write a program that answers: “Am I ready for the trip?”
Sample Output:
Did you pack your charger? (1 = Yes, 0 = No): 1
Did you pack your wallet? (1 = Yes, 0 = No): 1
Did you pack your ID? (1 = Yes, 0 = No): 1
Are you travelling internationally? (1 = Yes, 0 = No): 1
Did you pack your passport? (1 = Yes, 0 = No): 0
Am I ready for the trip? False
An airline allows a passenger to board the flight only if:
They have a valid boarding pass.
They have completed security.
They have arrived before the boarding gate closes.
Write a program that checks whether the passenger can board the flight.
Sample Output:
Do you have a boarding pass? (1 = Yes, 0 = No): 1
Have you completed security? (1 = Yes, 0 = No): 1
Did you arrive before the gate closed? (1 = Yes, 0 = No): 0
Can you board the flight? False