🔀 Python Conditional Statements 30 Practice Questions
Build a strong foundation in decision-making logic with hands-on exercises from basics to advanced scenarios, perfect for Python beginners and interview prep.
Your Learning Progress
🎓 Your Python Conditional Statements Learning Journey
Dive into the essentials of if, else, and elif to grasp how Python makes decisions based on conditions. Progress from simple true/false checks to nested logic that handles real-world variability. Along the way, you’ll tackle 10 beginner questions on basic syntax, 10 intermediate ones exploring logical operators and edge cases, and 10 advanced challenges involving optimization and pattern matching. By the end, you’ll confidently implement conditionals in scripts, functions, and larger projects. This path not only builds technical skills but also sharpens problem-solving for coding interviews and everyday programming. Track your mastery with interactive progress tools and earn completion badges for motivation.
🔰 Beginner Level Questions
Basic Number Sign Checker
Create a simple program that takes a user-input number and determines whether it is positive, negative, or zero using if-elif-else statements.
- Input Handling: Use input() to get an integer from the user.
- Condition Logic: Check if the number is greater than 0, less than 0, or equal to 0.
- Output Message: Print a descriptive message for each case.
Even or Odd Number Detector
Write a script that accepts a number and uses conditional statements to check if it is even or odd.
- Modulo Operator: Use % to determine divisibility by 2.
- Simple If-Else: Implement a binary decision with if-else.
- User Feedback: Output “Even” or “Odd” clearly.
Simple Grade Calculator
Build a program that takes a student’s score (0-100) and assigns a letter grade: A (90+), B (80-89), C (70-79), D (60-69), F (below 60).
- Score Input: Prompt for an integer score.
- Elif Chain: Use if-elif-else for multiple ranges.
- Edge Cases: Handle exactly 90, 80, etc.
Leap Year Identifier
Develop a tool to check if a given year is a leap year: divisible by 4, but not by 100 unless by 400.
- Nested Conditions: Use if with and/or for rules.
- Year Input: Accept integer year.
- Result Output: Print “Leap year” or “Not a leap year.”
Basic Password Length Validator
Create a checker that verifies if a password string is at least 8 characters long.
- String Length: Use len() in condition.
- If-Else: Approve or reject based on length.
- Input Prompt: Get password from user.
Temperature Category Advisor
Write a program that categorizes temperature as “Hot” (>30°C), “Warm” (20-30°C), “Cool” (10-19°C), or “Cold” (<10°C).
- Temp Input: Float input for Celsius.
- Elif Ladder: Chain conditions for ranges.
- Advice Output: Suggest clothing based on category.
Largest Number Finder Among Three
Implement logic to input three numbers and output the largest one using nested if statements.
- Multiple Inputs: Three separate input() calls.
- Nested Ifs: Compare pairwise.
- Result Print: “The largest is X.”
Vowel or Consonant Checker
Take a single character input and determine if it’s a vowel (a,e,i,o,u) or consonant, ignoring case.
- Character Input: Single letter via input().
- Or Conditions: If in ‘aeiou’ or ‘AEIOU’.
- Output: “Vowel” or “Consonant”.
Basic Calculator with Menu
Build a menu-driven calculator that performs add, subtract, multiply, or divide based on user choice.
- Choice Input: Number 1-4 for operations.
- If-Elif: Branch for each operation.
- Two Numbers: Input operands after choice.
Day of Week Translator
Input a number 1-7 and output the corresponding day name (1=Monday, etc.).
- Number Input: Integer 1-7.
- Elif Chain: For each day.
- Invalid Handling: Else for out-of-range.
⚡ Intermediate Level Questions
Voting Eligibility Checker
Enhance a program to check voting eligibility: age >=18 and citizen (yes/no), with nested conditions for additional rules like resident status.
- User Inputs: Age (int), citizenship (str), residency (str).
- Nested Ifs: Outer for age, inner for citizenship and residency.
- Detailed Output: Reasons for ineligibility.
FizzBuzz Generator
Implement FizzBuzz: for numbers 1 to n, print number or “Fizz” (div by 3), “Buzz” (div by 5), “FizzBuzz” (both), using conditionals in a loop.
- Loop Integration: For loop with if-elif-else inside.
- Modulo Checks: %3 and %5 with or/and.
- User n: Input for range.
Conditional Triangle Pattern Printer
Create a program that prints a right-angled triangle of stars, but only if height is 1-10; otherwise, print inverted if even.
- Height Input: Integer validation with if.
- Nested Loops: Outer for rows, inner with conditionals for direction.
- Shape Logic: Use if for even/odd height to decide print order.
Vowel Counter with Case Handling
Count vowels in a string, but categorize upper/lower and print counts if total >5, else summary.
- String Input: User phrase.
- Loop with Conditions: For each char, if vowel check case.
- Threshold If: Conditional output based on total vowels.
Conditional Maximum Finder in List
Given a list of numbers, find the maximum but ignore negatives if any positive exists, else find min.
- List Input: Hardcode or input list.
- Loop Conditions: Track has_positive, update max/min accordingly.
- Final Decision: If has_positive else min.
Simple User Login Simulator
Simulate login: 3 attempts, check username/password match hardcoded values, lock after fails.
- Loop Attempts: While with counter.
- Nested Conditions: If match both, login success; else increment fail.
- Lockout: If attempts >3, deny access.
Shopping Discount Calculator
Calculate total after discount: 10% if >100 and member, 5% if >100, none else; input amount and member status.
- Inputs: Amount (float), member (y/n).
- Nested If: Outer for amount >100, inner for member.
- Output Total: Discounted price.
Rock-Paper-Scissors Game Logic
Implement game: user vs computer choice, determine winner with conditional rules for ties/wins.
- Choices: Input user, random for computer.
- Complex Conditions: If-elif for each pair (rock>scissors, etc.).
- Score Tracking: Simple counter if win.
BMI Category Classifier
Calculate BMI from height/weight, classify as Underweight (<18.5), Normal (18.5-24.9), Overweight (25-29.9), Obese (>=30).
- Formula: weight / (height**2).
- Elif Ranges: Precise boundaries.
- Health Tip: Conditional advice per category.
Quiz Score Evaluator
Ask 5 true/false questions, score with conditionals, output pass/fail and percentage if passed.
- Questions Hardcoded: Simple facts.
- Loop with If: For each answer check.
- Final Conditional: If score >=80% pass.
🚀 Advanced Level Questions
Complex Form Validation System
Validate a registration form: email format, password strength (length, chars, numbers), age >18, with nested conditions and error collection.
- Multiple Inputs: Email, password, age, name.
- Deep Nesting: If all pass, register; else list errors.
- Regex-Like Checks: Simulate with string methods and conditions.
Simple Medical Diagnosis Decision Tree
Simulate a decision tree for flu diagnosis: symptoms (fever, cough, fatigue), branch with probabilities or severity levels.
- Symptom Inputs: Yes/no for each.
- Multi-Level Nesting: If fever and cough, high risk; else low.
- Recommendation: Conditional advice like “See doctor”.
Conditional File Line Processor
Read a text file, process lines: if contains keyword, uppercase; if length >50, truncate; else skip if empty.
- File Handling: Open and read lines.
- Per-Line Conditions: Nested if for multiple checks.
- Output File: Write processed to new file.
OOP Class with Conditional Behaviors
Define a BankAccount class: deposit/withdraw with conditions for overdraft, fees if balance <0, interest if >1000.
- Class Methods: Init with balance, conditional deposit/withdraw.
- Nested Logic: In methods, check balance before actions.
- Instance Test: Create and perform operations.
Optimized Conditional Search Function
Create a function to search a large list: linear with early exit if found, conditional on sorted/unsorted for binary if applicable.
- Function Params: List, target, sorted flag.
- Branching: If sorted, binary conditions; else linear.
- Performance: Return index or -1, with count of checks.
Traffic Light Simulation System
Simulate intersection: multiple lights, pedestrian cross conditional on vehicle presence, emergency override.
- State Vars: Lights as dict, vehicle/pedestrian bools.
- Complex Nesting: If emergency, all red; else cycle with conditions.
- Loop Simulation: Run for 10 cycles, print states.
Employee Payroll Processor with Overtime
Process payroll for list of employees: base pay, overtime if hours>40 (1.5x), tax brackets conditional on total.
- Employee List: Dict of names:hours.
- Per-Employee Calc: Nested if for overtime and taxes (10% <500, 20% 500-1000, 30% >1000).
- 📋 Requirements:$20/hr base; output table of net pays.
Advanced Weather Advisory System
Input temp, humidity, wind: alert levels – if temp<0 and wind>20 blizzard; humidity>80 and temp>30 humid heat; etc., with multi-factor nesting.
- Multi Inputs: Float for temp/hum/wind.
- Priority Conditions: Elif chain with compound and/or.
- Severity Scale: 1-5 based on combos.
Text Adventure Game with Branching Choices
Build a short text adventure: rooms with choices, inventory check conditions, win/lose based on decisions.
- State Management: Vars for position, inventory.
- Deep Conditional Branches: While loop with if-elif for choices.
- End Conditions: Win if key and door, else game over.
Conditional Data Analyzer for Sales Report
Process sales dict: filter high performers (>avg), conditional bonuses, categorize by region with nested logic.
- Data Structure: Dict of {region: [sales list]}.
- Advanced Filtering: Loop with multi-conditions for bonus eligibility.
- Report Generation: Print summary if total > threshold.