Conditional Statements — Practice Questions
100 questions. Try each one yourself before checking the answer.
Create number = 7. Print "Positive" only when the number is greater than zero.
Create number = -3. Print "Positive" when it is above zero, and "Not positive" otherwise.
Create age = 20 and print "Adult" only if the age is 18 or over. Nothing should print for a smaller age.
Create marks = 85. When the marks are 40 or above, print two lines: "Passed" and "Well done!". Both lines must be indented so they belong to the if.
Ask the user for a password. Print "Access granted" when it equals "python123", otherwise "Access denied".
Ask for a mark and print "Pass" when it is 40 or more, otherwise "Fail".
Ask for a number and print whether it is "Positive", "Negative" or "Zero" using three branches.
Ask for a temperature in Celsius and print "Hot" above 30, "Warm" from 20 to 30, and "Cold" below 20.
Ask for a number and print "In range" only when it is above 10 and below 20.
Ask for a day name and print "Weekend" when it is "Saturday" or "Sunday", otherwise "Weekday".
Ask whether it is raining (yes/no). Using not, print "Go outside" when it is not raining.
Ask for a single letter and print "Vowel" when it is one of aeiou, otherwise "Consonant".
Ask for an age and, only if the person is 18 or over, ask whether they have an ID and print whether they may enter.
Ask for a mark out of 100 and print a grade: A for 90+, B for 80+, C for 70+, D for 60+, otherwise F.
Ask for two numbers and print which one is larger, or that they are equal.
Ask for a number and print whether it is even or odd.
Ask for a username and print "Welcome back" only when it equals "admin" — remembering that comparison is case-sensitive.
Fix the case-sensitivity problem: accept admin, Admin or ADMIN by lowercasing the input before comparing.
Ask for a name. Using the string itself as the condition, print "Hello, <name>" when something was typed and "You typed nothing" when it was left empty.
Create count = 0 and use it directly as a condition to print "Nothing in stock", then repeat with count = 5 to print the stock level.
Create result = None and print "No result yet" when it is None, otherwise print the result. Use is None, not == None.
Ask for a number and print "Even" or "Odd" using a conditional expression (a one-line if/else) inside the print().
Ask for a mark and store "Pass" or "Fail" in a variable using a conditional expression, then print the variable.
Ask for a mark and print "Valid" only when it falls between 0 and 100, using a single chained comparison in the condition.
Ask for a filename and print "Image file" when it ends with .jpg or .png, otherwise "Other file".
Ask for three numbers and print the largest, using nested if statements.
Solve the same problem again — largest of three — but this time with a flat if/elif/else using and. Compare how readable the two versions are.
Ask for a year and print whether it is a leap year, using the full rule: divisible by 4, but not by 100 unless it is also divisible by 400.
Rewrite the leap-year check as a single condition using and, or and brackets.
Ask for a mark and print a grade with a +/- refinement: A+ for 95+, A for 90+, B+ for 85+, B for 80+, C for 70+, otherwise F.
Ask for weight in kg and height in metres, work out the BMI, then print the category: Underweight below 18.5, Normal below 25, Overweight below 30, otherwise Obese.
Ask for an age and print the life stage: Child under 13, Teenager under 20, Adult under 60, otherwise Senior.
Ask for a number and print "FizzBuzz" when it divides by both 3 and 5, "Fizz" for 3 only, "Buzz" for 5 only, otherwise the number itself. Think carefully about which check must come first.
Ask for a username and password. Grant access only when the username is admin and the password is python123, and give a different message for each kind of failure.
Ask for a purchase amount and apply a discount: 20% above 5000, 10% above 2000, 5% above 1000, otherwise none. Print the discount and the final amount.
Ask for units of electricity consumed and calculate the bill using slabs: first 100 units at 3.50, next 200 at 4.50, anything beyond at 6.50.
Ask for an annual income and calculate tax using slabs: nothing up to 250000, 5% on the part from 250001 to 500000, 20% on the part from 500001 to 1000000, 30% above that.
Ask for three side lengths and print the triangle type: Equilateral if all three match, Isosceles if exactly two match, otherwise Scalene.
Extend the previous idea: first check the three sides can actually form a triangle (each pair must add to more than the third). Only then report the type.
Ask for a number from 1 to 7 and print the matching day of the week, with a sensible message for anything out of range.
Ask for a month number and a year, and print how many days that month has — handling February correctly for leap years.
Ask for a month number and print the season: Winter for 12/1/2, Spring for 3–5, Summer for 6–8, Autumn for 9–11.
Ask for an age and print the ticket price: free under 5, 50 for under 18, 150 for adults, 80 for 60 and over.
Ask for a parcel weight in kg and print the shipping cost: 50 up to 1 kg, 80 up to 5 kg, 150 up to 10 kg, otherwise 150 plus 20 for every kg above 10.
Ask for a password and print a strength rating: Weak below 6 characters, Medium below 10, Strong at 10 or more — but Weak regardless if it contains a space.
Ask for a traffic light colour and print the correct action, rejecting anything that is not red, amber or green.
Play one round of rock-paper-scissors. Ask both players for their choice and print who wins.
Build a single-use calculator. Show a menu of add, subtract, multiply and divide, ask for the choice and two numbers, then print the result. Guard against dividing by zero.
Build a single-use unit converter menu: km to miles, kg to pounds, or Celsius to Fahrenheit.
Ask for a mark and use nested conditional expressions on one line to print "A" for 80+, "B" for 60+, otherwise "C". Then note in a comment when this stops being readable.
Build a single ATM transaction. Starting from balance = 5000, offer check balance, deposit or withdraw, and reject a withdrawal larger than the balance.
Ask for marks in three subjects. Print the total, the percentage, and a result of Pass only when every subject is 40 or above.
Ask for a movie seat class (silver, gold, platinum) and the number of tickets, then print the total, applying a 10% discount when 5 or more tickets are bought.
Ask how many hours a car was parked and print the fee: 20 for the first hour, 15 for each additional hour, capped at 150 for the day.
Ask for monthly call minutes and data GB, then recommend a plan: Basic under 300 minutes and under 5 GB, Standard under 800 and under 20, otherwise Premium.
Ask for a student's attendance percentage and average marks. Allow them to sit the exam only when attendance is at least 75 and marks are at least 40; explain the specific reason when they cannot.
Ask for a hotel room type and the season (peak or off), then print the nightly rate. Peak season adds 40% to every room type.
Ask for a taxi journey's distance in km and whether surge pricing applies. Charge a base fare of 50 covering the first 2 km, then 12 per km, and add 50% when surge is on.
Ask how many days late a library book is and print the fine: nothing for 0 days, 2 per day up to 7 days, 5 per day beyond that, capped at 200.
Build a currency converter menu offering USD, EUR and GBP from rupees, using fixed rates of 83, 90 and 105.
Build a temperature converter that asks the user which direction they want (C to F, or F to C) and converts accordingly.
Ask for a restaurant order: a main dish and whether the customer wants a drink and dessert. A main plus both extras is a combo priced at 350; otherwise charge 250, 60 and 80 separately.
Ask for an email address and print a specific complaint for each problem: no @, no . after the @, or nothing before the @. Print "Looks valid" only when all checks pass.
Ask for a gym membership length in months and print the plan and total: Monthly at 1500, Quarterly at 4000 for 3, Half-yearly at 7500 for 6, Annual at 14000 for 12.
Ask for a shipping zone (local, national, international) and a weight, then print the cost using a different per-kg rate and base fee for each zone.
Ask for a mark and print both the letter grade and a comment: Excellent for A, Good for B, Satisfactory for C, and Needs work for anything lower.
Ask for a PIN and validate it: it must be exactly 4 characters, all digits, and not one of the obvious ones (0000 or 1234). Give a specific reason for each failure.
Ask for the current hour as a number from 0 to 23 and print the right greeting: Good morning before 12, Good afternoon before 17, Good evening before 21, Good night otherwise.
Ask for a quantity and a unit price. Apply a bulk rate of 10% off for 50 or more units and 20% off for 100 or more, then print an itemised total.
Build a one-question quiz. Show the question and four options, take the answer, and print whether it was right along with the correct answer.
This is meant to print "Well done" only for a pass, but it prints for everyone. Find and fix the bug.
marks = 20
if marks >= 40:
print("Passed")
print("Well done")Show the difference between an elif chain and a run of separate if statements, using a mark of 95 and grade boundaries at 90, 80 and 70.
Explain why if marks = 40: is a SyntaxError, and give the correct version.
Show that the string "0" and the number 0 behave differently as conditions, and explain why this matters when reading input().
Show why ordering matters in an elif chain: write a grade check with the boundaries in the wrong order so that a mark of 95 gets the wrong grade, then fix it.
Use short-circuit evaluation inside a condition to safely check an average without ever dividing by zero.
Given value = None, show that checking is None before using the value avoids a crash, and what happens if you get the order wrong.
Show the trap in using in to test for a whole word: check whether "cat" appears in "concatenate" and explain the result.
Show why comparing floats with == inside a condition is unreliable, and give the correct approach.
Rewrite this deeply nested check as a flat if/elif/else that fails fast, and explain why the flat version is easier to maintain.
if age >= 18:
if has_id:
if not banned:
print("Allowed")This always reports "Too young", even for an adult. Find and fix the bug.
age = input("Enter age: ")
if age >= 18:
print("Adult")
else:
print("Too young")This menu rejects perfectly good input. Find and fix the bug.
choice = input("Choose (1-3): ")
if choice == 1:
print("You chose one")
else:
print("Invalid choice")This login check accepts the wrong password. Find and fix the bug.
username = input("Username: ")
password = input("Password: ")
if username == "admin" or password == "secret":
print("Access granted")
else:
print("Access denied")This menu rejects "YES" and " yes". Make it accept any reasonable spelling.
answer = input("Continue? (yes/no): ")
if answer == "yes":
print("Continuing")
else:
print("Stopping")Explain the difference between if value: and if value == True: by testing both against 1, "hello" and True.
Build a Report Card Generator. Ask for a student's name and three subject marks, then print a bordered card with each mark, the total, percentage, grade, and pass/fail based on every subject reaching 40.
Build a Number Classifier. Ask for a number and print a full report: positive/negative/zero, even/odd, whether it is a whole number, whether it is in the range 1–100, and how many digits its whole part has.
Build a Restaurant Bill Calculator. Ask for the food total, whether the customer is a member, and the service rating out of 5. Apply a 10% member discount, add 5% tax, and add a tip of 15% for a rating of 4 or more, 10% for 3, and none below that.
Build a Login Validator. Ask for a username and password and check, in order: username not empty, username at least 4 characters, password at least 8 characters, password contains no spaces, and both match the stored credentials. Report the first problem found.
Build an Electricity Bill Generator. Ask for the customer name, units consumed and connection type (domestic or commercial). Use slab rates for domestic and a flat higher rate for commercial, add 5% tax, and print an itemised bill.
Build a Triangle Analyser. Ask for three sides, check they form a valid triangle, then report the type by sides (equilateral/isosceles/scalene) and whether it is right-angled.
Build an Income Tax Calculator. Ask for the annual income and age group (general, senior, super-senior), apply the matching exemption limit, then calculate the tax across slabs and print a summary.
Build a Three-Question Quiz. Ask three questions, track the score, and print the final score with a grade and message.
Build a Shipping Cost Estimator. Ask for the destination zone, weight, and whether express delivery is wanted. Apply zone rates, add 60% for express, and offer free shipping for local orders under 1 kg.
Build a Smart Unit Converter. Offer a menu of length, weight and temperature; then ask for the direction within that category and convert accordingly. Handle invalid choices at both levels.
Explain why elif exists at all, given that nested if/else can express the same logic. Demonstrate both forms for a four-band grade check.
Write a leap-year check and explain each part of the rule in comments, including why the 100/400 exceptions exist.
Given a mark, produce the grade using a conditional expression chain, then the same result with an if/elif chain, and state clearly when each style is appropriate.
Write a validation routine using guard clauses that checks an order: quantity above zero, quantity at most 100, and stock available. Explain why checking for failure first is preferred over deep nesting.
Build a Loan Decision Engine — the fullest demonstration of this topic. Ask for the applicant's age, monthly income, credit score, existing loan count and employment type. Work out each criterion, print every check, compute a risk band, and give a final decision with the reason for any rejection.
Still stuck on something?
Book a free 1-on-1 session and we'll work through it together.
Book a Free Session