Python · Python Fundamentals

Conditional Statements — Practice Questions

100 questions. Try each one yourself before checking the answer.

Q1ifEasy

Create number = 7. Print "Positive" only when the number is greater than zero.

Q2if / elseEasy

Create number = -3. Print "Positive" when it is above zero, and "Not positive" otherwise.

Q3ifEasy

Create age = 20 and print "Adult" only if the age is 18 or over. Nothing should print for a smaller age.

Q4IndentationEasy

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.

Q5if / elseEasy

Ask the user for a password. Print "Access granted" when it equals "python123", otherwise "Access denied".

Q6if / elseEasy

Ask for a mark and print "Pass" when it is 40 or more, otherwise "Fail".

Q7if / elif / elseEasy

Ask for a number and print whether it is "Positive", "Negative" or "Zero" using three branches.

Q8if / elif / elseEasy

Ask for a temperature in Celsius and print "Hot" above 30, "Warm" from 20 to 30, and "Cold" below 20.

Q9Logical OperatorsEasy

Ask for a number and print "In range" only when it is above 10 and below 20.

Q10Logical OperatorsEasy

Ask for a day name and print "Weekend" when it is "Saturday" or "Sunday", otherwise "Weekday".

Q11Logical OperatorsEasy

Ask whether it is raining (yes/no). Using not, print "Go outside" when it is not raining.

Q12MembershipEasy

Ask for a single letter and print "Vowel" when it is one of aeiou, otherwise "Consonant".

Q13Nested ifEasy

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.

Q14if / elif / elseEasy

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.

Q15ComparisonEasy

Ask for two numbers and print which one is larger, or that they are equal.

Q16ComparisonEasy

Ask for a number and print whether it is even or odd.

Q17String ConditionsEasy

Ask for a username and print "Welcome back" only when it equals "admin" — remembering that comparison is case-sensitive.

Q18String ConditionsEasy

Fix the case-sensitivity problem: accept admin, Admin or ADMIN by lowercasing the input before comparing.

Q19TruthinessEasy

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.

Q20TruthinessEasy

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.

Q21NoneEasy

Create result = None and print "No result yet" when it is None, otherwise print the result. Use is None, not == None.

Q22TernaryEasy

Ask for a number and print "Even" or "Odd" using a conditional expression (a one-line if/else) inside the print().

Q23TernaryEasy

Ask for a mark and store "Pass" or "Fail" in a variable using a conditional expression, then print the variable.

Q24ComparisonEasy

Ask for a mark and print "Valid" only when it falls between 0 and 100, using a single chained comparison in the condition.

Q25String ConditionsEasy

Ask for a filename and print "Image file" when it ends with .jpg or .png, otherwise "Other file".

Q26Nested ifMedium

Ask for three numbers and print the largest, using nested if statements.

Q27Logical OperatorsMedium

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.

Q28Nested ifMedium

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.

Q29Logical OperatorsMedium

Rewrite the leap-year check as a single condition using and, or and brackets.

Q30GradingMedium

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.

Q31ClassificationMedium

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.

Q32ClassificationMedium

Ask for an age and print the life stage: Child under 13, Teenager under 20, Adult under 60, otherwise Senior.

Q33LogicMedium

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.

Q34ValidationMedium

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.

Q35BillingMedium

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.

Q36Slab LogicMedium

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.

Q37Slab LogicMedium

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.

Q38ClassificationMedium

Ask for three side lengths and print the triangle type: Equilateral if all three match, Isosceles if exactly two match, otherwise Scalene.

Q39Nested ifMedium

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.

Q40LookupMedium

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.

Q41CalendarMedium

Ask for a month number and a year, and print how many days that month has — handling February correctly for leap years.

Q42CalendarMedium

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.

Q43BillingMedium

Ask for an age and print the ticket price: free under 5, 50 for under 18, 150 for adults, 80 for 60 and over.

Q44BillingMedium

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.

Q45ValidationMedium

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.

Q46LookupMedium

Ask for a traffic light colour and print the correct action, rejecting anything that is not red, amber or green.

Q47Game LogicMedium

Play one round of rock-paper-scissors. Ask both players for their choice and print who wins.

Q48Menu-DrivenMedium

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.

Q49Menu-DrivenMedium

Build a single-use unit converter menu: km to miles, kg to pounds, or Celsius to Fahrenheit.

Q50TernaryMedium

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.

Q51Menu-DrivenMedium

Build a single ATM transaction. Starting from balance = 5000, offer check balance, deposit or withdraw, and reject a withdrawal larger than the balance.

Q52ClassificationMedium

Ask for marks in three subjects. Print the total, the percentage, and a result of Pass only when every subject is 40 or above.

Q53BillingMedium

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.

Q54BillingMedium

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.

Q55ClassificationMedium

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.

Q56ValidationMedium

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.

Q57BillingMedium

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.

Q58BillingMedium

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.

Q59Slab LogicMedium

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.

Q60Menu-DrivenMedium

Build a currency converter menu offering USD, EUR and GBP from rupees, using fixed rates of 83, 90 and 105.

Q61Menu-DrivenMedium

Build a temperature converter that asks the user which direction they want (C to F, or F to C) and converts accordingly.

Q62BillingMedium

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.

Q63ValidationMedium

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.

Q64ClassificationMedium

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.

Q65BillingMedium

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.

Q66GradingMedium

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.

Q67ValidationMedium

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.

Q68LookupMedium

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.

Q69BillingMedium

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.

Q70Menu-DrivenMedium

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.

Q71DebuggingHard

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")
Q72LogicHard

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.

Q73DebuggingHard

Explain why if marks = 40: is a SyntaxError, and give the correct version.

Q74TruthinessHard

Show that the string "0" and the number 0 behave differently as conditions, and explain why this matters when reading input().

Q75LogicHard

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.

Q76LogicHard

Use short-circuit evaluation inside a condition to safely check an average without ever dividing by zero.

Q77NoneHard

Given value = None, show that checking is None before using the value avoids a crash, and what happens if you get the order wrong.

Q78MembershipHard

Show the trap in using in to test for a whole word: check whether "cat" appears in "concatenate" and explain the result.

Q79ComparisonHard

Show why comparing floats with == inside a condition is unreliable, and give the correct approach.

Q80LogicHard

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")
Q81DebuggingHard

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")
Q82DebuggingHard

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")
Q83DebuggingHard

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")
Q84DebuggingHard

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")
Q85LogicHard

Explain the difference between if value: and if value == True: by testing both against 1, "hello" and True.

Q86Mini-ProjectMini-Project

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.

Q87Mini-ProjectMini-Project

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.

Q88Mini-ProjectMini-Project

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.

Q89Mini-ProjectMini-Project

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.

Q90Mini-ProjectMini-Project

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.

Q91Mini-ProjectMini-Project

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.

Q92Mini-ProjectMini-Project

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.

Q93Mini-ProjectMini-Project

Build a Three-Question Quiz. Ask three questions, track the score, and print the final score with a grade and message.

Q94Mini-ProjectMini-Project

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.

Q95Mini-ProjectMini-Project

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.

Q96InterviewInterview

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.

Q97InterviewInterview

Write a leap-year check and explain each part of the rule in comments, including why the 100/400 exceptions exist.

Q98InterviewInterview

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.

Q99InterviewInterview

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.

Q100CapstoneInterview

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