20 practical Python questions based on if-else statements.
Each
question is designed to simulate real-world scenarios, making the
concepts relatable and engaging.
1. Discount Calculator
Write a program that takes the price of a product as input.
If the price is greater than ₹500, apply a 10% discount; otherwise, apply a 5% discount. Display
the final price.
2. Odd or Even
Take the user's age as input.
If the age is 18 or above, display "Eligible to drive"; otherwise, display "Not eligible to drive."
3. Driving Eligibility
Take the user's age as input.
If the age is 18 or above, display "Eligible to drive"; otherwise, display "Not eligible to drive."
4. Store Timing
Write a program that asks the current time (24-hour format).
If the time is between 9 AM and 9 PM, print "Store is open"; otherwise, print "Store is closed."
5. Pass or Fail
Take the user's marks as input.
If the marks are 40 or above, print "Pass"; otherwise, print "Fail."
6. Prime Membership
Write a program that asks if the user has a Prime membership.
If the user enters "yes," offer free delivery; otherwise, charge ₹50 for delivery.
7. Leap Year Checker
Take a year as input.
Check if it is a leap year or not using an if-else statement.
8. Temperature Alert
Take the current temperature as input.
If the temperature is above 40°C, display "Heat Alert"; if it’s below 0°C, display "Cold Alert";
otherwise, display "Normal Weather."
9. Grade Calculator
Ask the user for their percentage marks.
Use if-else statements to print the grade based on the following:
90% and above: A+
80%–89%: A
70%–79%: B
Below 70%: C
10. Bank Withdrawal
Take the balance in a bank account and the amount the user wants to withdraw as input. If
the withdrawal amount is less than or equal to the balance, print "Withdrawal successful";
otherwise, print "Insufficient balance."
11. Number Comparison
Ask the user to input two numbers.
Print whether the first number is greater, smaller, or equal to the second number.
12. Password Validator
Ask the user to input a password.
If it matches a predefined password (e.g., "secure123"), print "Access granted"; otherwise, print
"Access denied."
13. Evening Discount
If the current time is between 6 PM and 9 PM, apply a 20% discount on the product price
entered by the user. Otherwise, no discount is applied.
14. Eligible for Voting
Take the user's citizenship ("Indian" or "Other") and age as input.
If the user is Indian and 18 or above, print "Eligible to vote"; otherwise, print "Not eligible to
vote."
15. Restaurant Bill Split
Ask the user for the number of people in a group.
If it’s greater than 5, apply a 15% service charge on the total bill amount entered by the user.
16. Delivery Service
Ask for the user's delivery location (as "urban" or "rural").
If the location is urban, display "Delivery available"; otherwise, display "Delivery not available."
17. BMI Calculator
Take the user’s weight (in kg) and height (in meters) as input and calculate their BMI.
If BMI < 18.5, display "Underweight"; 18.5–24.9, display "Normal"; otherwise, display
"Overweight."
18. Weekend Check
Ask the user to input a day of the week.
If it’s Saturday or Sunday, print "Weekend"; otherwise, print "Weekday."
19. Flight Fare Check
Take the age of a passenger as input.
If the passenger is below 12 or above 60, apply a 50% discount on the fare entered by the user;
otherwise, charge the full fare.
20. Electricity Bill
Ask the user for the number of electricity units consumed.
If units are:
Less than or equal to 100: Charge ₹5 per unit.
Between 101 and 300: Charge ₹10 per unit.
Above 300: Charge ₹15 per unit.