Question Mentor Logo Question Mentor
Practice With AI
Home » Directory » Practice Questions » Python Conditional Statements 30 Practice Questions

Python Conditional Statements 30 Practice Questions

Python Conditional Statements 30 Practice Questions | QuestionMentor

🔀 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.

📚 30 Questions ⏱️ 4-6 Hours 🎯 Beginner to Advanced 💻 Python 3.x 🔥 100% Practical

Your Learning Progress

0/30 Completed
Beginner 10
Intermediate 10
Advanced 10

🎓 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

Question #1
🔰 Beginner ⏱️ 15 min Mark Complete

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.
📋 Requirements:
Handle only integer inputs; no error handling for non-integers required. Ensure exact phrasing in outputs like “The number is positive.”
Question #2
🔰 Beginner ⏱️ 15 min Mark Complete

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.
📋 Requirements:
Input must be converted to int; test with both even and odd numbers like 4 and 7.
Question #3
🔰 Beginner ⏱️ 20 min Mark Complete

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.
📋 Requirements:
Use >= for boundaries; output format: “Your grade is A.”
Question #4
🔰 Beginner ⏱️ 20 min Mark Complete

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.”
📋 Requirements:
Test with 2000 (yes), 1900 (no), 2024 (yes); no need for dates beyond year.
Question #5
🔰 Beginner ⏱️ 15 min Mark Complete

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.
📋 Requirements:
Output “Password accepted” or “Password too short”; case-sensitive input.
Question #6
🔰 Beginner ⏱️ 20 min Mark Complete

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.
📋 Requirements:
Use >= and <= appropriately; example output: "It's Hot - wear light clothes."
Question #7
🔰 Beginner ⏱️ 25 min Mark Complete

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.”
📋 Requirements:
Handle ties by printing any; convert inputs to int.
Question #8
🔰 Beginner ⏱️ 15 min Mark Complete

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”.
📋 Requirements:
Use lower() for case insensitivity; assume alphabetic input.
Question #9
🔰 Beginner ⏱️ 25 min Mark Complete

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.
📋 Requirements:
No division by zero check; output result as float.
Question #10
🔰 Beginner ⏱️ 20 min Mark Complete

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.
📋 Requirements:
Output “Invalid day” for others; start with Monday as 1.

⚡ Intermediate Level Questions

Question #11
⚡ Intermediate ⏱️ 30 min Mark Complete

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.
📋 Requirements:
Case-insensitive string checks; test scenarios like underage citizen, adult non-resident.
Question #12
⚡ Intermediate ⏱️ 40 min Mark Complete

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.
📋 Requirements:
n up to 100; each on new line, no extra spaces.
Question #13
⚡ Intermediate ⏱️ 35 min Mark Complete

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.
📋 Requirements:
Error message for invalid height; use ‘*’ for stars.
Question #14
⚡ Intermediate ⏱️ 30 min Mark Complete

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.
📋 Requirements:
Use isupper()/islower(); output format: “Upper vowels: 2, Lower: 3”.
Question #15
⚡ Intermediate ⏱️ 40 min Mark Complete

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.
📋 Requirements:
List size 5-10; handle all negative or mixed.
Question #16
⚡ Intermediate ⏱️ 45 min Mark Complete

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.
📋 Requirements:
Hardcode ‘admin’/’password123’; output “Access granted” or “Locked out”.
Question #17
⚡ Intermediate ⏱️ 35 min Mark Complete

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.
📋 Requirements:
Round to 2 decimals; format: “Total: $XX.XX”.
Question #18
⚡ Intermediate ⏱️ 50 min Mark Complete

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.
📋 Requirements:
Import random; play one round, output winner.
Question #19
⚡ Intermediate ⏱️ 30 min Mark Complete

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.
📋 Requirements:
Inputs in meters/kg; output BMI and category.
Question #20
⚡ Intermediate ⏱️ 45 min Mark Complete

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.
📋 Requirements:
Input ‘t’/’f’; output “Passed with XX%”.

🚀 Advanced Level Questions

Question #21
🚀 Advanced ⏱️ 60 min Mark Complete

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.
📋 Requirements:
Password: >8, has digit, has letter; email has @; output error list or “Registered”.
Question #22
🚀 Advanced ⏱️ 90 min Mark Complete

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”.
📋 Requirements:
Count symptoms for severity; output risk level and action.
Question #23
🚀 Advanced ⏱️ 75 min Mark Complete

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.
📋 Requirements:
Keyword “error”; assume small file; no exceptions.
Question #24
🚀 Advanced ⏱️ 80 min Mark Complete

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.
📋 Requirements:
$5 fee on negative; 1% interest on high; print status after each.
Question #25
🚀 Advanced ⏱️ 70 min Mark Complete

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.
📋 Requirements:
List size 1000; test both modes.
Question #26
🚀 Advanced ⏱️ 100 min Mark Complete

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.
📋 Requirements:
States: red/yellow/green; random events for vehicles.
Question #27
🚀 Advanced ⏱️ 85 min Mark Complete

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.
Question #28
🚀 Advanced ⏱️ 95 min Mark Complete

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.
📋 Requirements:
Define 5+ scenarios; output alert level and description.
Question #29
🚀 Advanced ⏱️ 120 min Mark Complete

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.
📋 Requirements:
3 rooms, 2-3 choices each; input numbers for options.
Question #30
🚀 Advanced ⏱️ 110 min Mark Complete

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.
📋 Requirements:
Hardcode sample data; bonus 10% if >1000 and region==’North’.
Share:
FEEDBACK