← Back to Home

37 Practice Questions: Conditional Statements

By Instructor

A complete practice collection of 37 Python Conditional Statements problems with solutions and output examples across 8 parts.

Covers basic if-else, multi-branch if-elif-else, nested if-else, f-string formatting, user input handling, and advanced real-world challenge problems.

By Instructor37 Problems8 PartsBeginner to Advanced
questions_demo.py
marks = 85

if marks >= 90:
    grade = "A+"
elif marks >= 80:
    grade = "A"

print(f"Grade: {grade}")
python questions_demo.py → Grade: A
Part 1

Basic If / Else (Questions 1 – 5)

Question 1 – Voting Eligibility

Create a variable age = 20. Check whether the person is eligible to vote (age 18 or above).

q01_voting.py
age = 20

if age >= 18:
    print("You are eligible to vote.")
else:
    print("You are not eligible to vote.")
Output:

You are eligible to vote.

Question 2 – Pass or Fail

Create a variable marks = 75. Check whether the student passed or failed (Passing marks are 40).

q02_pass_fail.py
marks = 75

if marks >= 40:
    print("You passed the exam.")
else:
    print("You failed the exam.")
Output:

You passed the exam.

Question 3 – Even or Odd

Create a variable number = 12. Check whether the number is even or odd.

q03_even_odd.py
number = 12

if number % 2 == 0:
    print("The number is even.")
else:
    print("The number is odd.")
Output:

The number is even.

Question 4 – Positive, Negative or Zero

Create a variable number = -10. Check whether the number is positive, negative or zero.

q04_sign.py
number = -10

if number > 0:
    print("The number is positive.")
elif number < 0:
    print("The number is negative.")
else:
    print("The number is zero.")
Output:

The number is negative.

Question 5 – Password Check

Create a variable password = "python123". Check whether the password is correct.

q05_password.py
password = "python123"

if password == "python123":
    print("Login successful.")
else:
    print("Wrong password.")
Output:

Login successful.

Part 2

If / Elif / Else Multi-Branch (Questions 6 – 10)

Question 6 – Grade Calculator

Create marks = 85. Conditions: 90+ = A+, 80-89 = A, 70-79 = B, 60-69 = C, 40-59 = D, Below 40 = Fail.

q06_grades.py
marks = 85

if marks >= 90:
    print("Grade A+")
elif marks >= 80:
    print("Grade A")
elif marks >= 70:
    print("Grade B")
elif marks >= 60:
    print("Grade C")
elif marks >= 40:
    print("Grade D")
else:
    print("Fail")
Output:

Grade A

Question 7 – Age Category

Create age = 25. Categories: 0-12 Child, 13-19 Teenager, 20-59 Adult, 60+ Senior Citizen.

q07_age_category.py
age = 25

if age <= 12:
    print("Child")
elif age <= 19:
    print("Teenager")
elif age <= 59:
    print("Adult")
else:
    print("Senior Citizen")
Output:

Adult

Question 8 – Temperature Classification

Create temperature = 35. Above 35 Very Hot, 25-35 Hot, 15-24 Normal, Below 15 Cold.

q08_temperature.py
temperature = 35

if temperature > 35:
    print("Very Hot")
elif temperature >= 25:
    print("Hot")
elif temperature >= 15:
    print("Normal")
else:
    print("Cold")
Output:

Hot

Question 9 – Day Checker

Create day = 3. Display day name according to number 1 to 7.

q09_day_checker.py
day = 3

if day == 1:
    print("Monday")
elif day == 2:
    print("Tuesday")
elif day == 3:
    print("Wednesday")
elif day == 4:
    print("Thursday")
elif day == 5:
    print("Friday")
elif day == 6:
    print("Saturday")
elif day == 7:
    print("Sunday")
else:
    print("Invalid day")
Output:

Wednesday

Question 10 – Salary Category

Create salary = 35000. 50000+ High, 30000-49999 Good, 20000-29999 Average, Below 20000 Low.

q10_salary.py
salary = 35000

if salary >= 50000:
    print("High Salary")
elif salary >= 30000:
    print("Good Salary")
elif salary >= 20000:
    print("Average Salary")
else:
    print("Low Salary")
Output:

Good Salary

Part 3

Nested If Statements (Questions 11 – 14)

Question 11 – Nested Login System

Create username = "admin", password = "1234". Check credentials using nested if.

q11_nested_login.py
username = "admin"
password = "1234"

if username == "admin":
    if password == "1234":
        print("Login successful.")
    else:
        print("Wrong password.")
else:
    print("Invalid username.")
Output:

Login successful.

Question 12 – Driving Eligibility

Create age = 22, has_license = True. Check eligibility using nested if.

q12_driving.py
age = 22
has_license = True

if age >= 18:
    if has_license:
        print("You can drive.")
    else:
        print("License required.")
else:
    print("You are too young to drive.")
Output:

You can drive.

Question 13 – Student Result (Marks + Attendance)

Create marks = 75, attendance = 80. Marks >= 40 and Attendance >= 75 required.

q13_student_result.py
marks = 75
attendance = 80

if marks >= 40:
    if attendance >= 75:
        print("You passed the exam.")
    else:
        print("You failed because of low attendance.")
else:
    print("You failed because of low marks.")
Output:

You passed the exam.

Question 14 – Loan Eligibility

Create age = 25, salary = 40000. Age >= 18 and Salary >= 30000 required.

q14_loan.py
age = 25
salary = 40000

if age >= 18:
    if salary >= 30000:
        print("Loan approved.")
    else:
        print("Salary is too low.")
else:
    print("Age is not eligible.")
Output:

Loan approved.

Part 4

F-String Formatting (Questions 15 – 19)

Question 15 – Personal Information

Create name = "Gagan", age = 24. Print using f-string.

q15_personal.py
name = "Gagan"
age = 24

print(f"My name is {name} and I am {age} years old.")
Output:

My name is Gagan and I am 24 years old.

Question 16 – Student Information

Create name = "Rahul", marks = 85. Print using f-string.

q16_student_info.py
name = "Rahul"
marks = 85

print(f"{name} scored {marks} marks.")
Output:

Rahul scored 85 marks.

Question 17 – Product Information

Create product = "Laptop", price = 55000. Print using f-string.

q17_product_info.py
product = "Laptop"
price = 55000

print(f"{product} costs ₹{price}.")
Output:

Laptop costs ₹55000.

Question 18 – Grade with F-String

Calculate grade for name = "Gagan", marks = 85 and display with f-string.

q18_grade_fstring.py
name = "Gagan"
marks = 85

if marks >= 90:
    grade = "A+"
elif marks >= 80:
    grade = "A"
elif marks >= 70:
    grade = "B"
elif marks >= 60:
    grade = "C"
elif marks >= 40:
    grade = "D"
else:
    grade = "Fail"

print(f"{name} scored {marks} marks and got Grade {grade}.")
Output:

Gagan scored 85 marks and got Grade A.

Question 19 – Voting Eligibility with F-String

Check voting eligibility for name = "Gagan", age = 24 using f-string.

q19_voting_fstring.py
name = "Gagan"
age = 24

if age >= 18:
    print(f"{name} is eligible to vote.")
else:
    print(f"{name} is not eligible to vote.")
Output:

Gagan is eligible to vote.

Part 5

User Input Basics (Questions 20 – 25)

Question 20 – Name and Age Input

q20_user_info.py
name = input("Enter your name: ")
age = int(input("Enter your age: "))

print(f"Hello {name}, you are {age} years old.")

Question 21 – User Input Even or Odd

q21_user_even_odd.py
number = int(input("Enter a number: "))

if number % 2 == 0:
    print(f"{number} is an even number.")
else:
    print(f"{number} is an odd number.")

Question 22 – User Input Voting Eligibility

q22_user_voting.py
age = int(input("Enter your age: "))

if age >= 18:
    print(f"You are {age} years old and you are eligible to vote.")
else:
    print(f"You are {age} years old and you are not eligible to vote.")

Question 23 – User Input Positive, Negative or Zero

q23_user_sign.py
number = int(input("Enter a number: "))

if number > 0:
    print(f"{number} is positive.")
elif number < 0:
    print(f"{number} is negative.")
else:
    print(f"{number} is zero.")

Question 24 – User Input Pass or Fail

q24_user_pass_fail.py
marks = int(input("Enter your marks: "))

if marks >= 40:
    print(f"You scored {marks} marks and passed the exam.")
else:
    print(f"You scored {marks} marks and failed the exam.")

Question 25 – User Input Password Check

q25_user_password.py
password = input("Enter password: ")

if password == "python123":
    print("Login successful.")
else:
    print("Wrong password.")
Part 6

User Input + Elif (Questions 26 – 28)

Question 26 – User Input Grade Calculator

q26_user_grades.py
marks = int(input("Enter your marks: "))

if marks >= 90:
    grade = "A+"
elif marks >= 80:
    grade = "A"
elif marks >= 70:
    grade = "B"
elif marks >= 60:
    grade = "C"
elif marks >= 40:
    grade = "D"
else:
    grade = "Fail"

print(f"You scored {marks} marks and your grade is {grade}.")

Question 27 – User Input Age Category

q27_user_age_category.py
age = int(input("Enter your age: "))

if age <= 12:
    category = "Child"
elif age <= 19:
    category = "Teenager"
elif age <= 59:
    category = "Adult"
else:
    category = "Senior Citizen"

print(f"You are {age} years old and you are an {category}.")

Question 28 – User Input Dynamic Calculator

q28_user_calculator.py
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
operator = input("Enter operator (+, -, *, /): ")

if operator == "+":
    result = num1 + num2
elif operator == "-":
    result = num1 - num2
elif operator == "*":
    result = num1 * num2
elif operator == "/":
    result = num1 / num2
else:
    result = None
    print("Invalid operator.")

if result is not None:
    print(f"{num1} {operator} {num2} = {result}")
Part 7

User Input + Nested If (Questions 29 – 32)

Question 29 – User Input Login System

q29_user_login.py
username = input("Enter username: ")
password = input("Enter password: ")

if username == "admin":
    if password == "1234":
        print("Login successful.")
    else:
        print("Wrong password.")
else:
    print("Invalid username.")

Question 30 – User Input Driving Eligibility

q30_user_driving.py
age = int(input("Enter your age: "))
has_license = input("Do you have a driving license? (yes/no): ")

if age >= 18:
    if has_license == "yes":
        print("You can drive.")
    else:
        print("License required.")
else:
    print("You are not eligible to drive.")

Question 31 – User Input Student Result

q31_user_student_result.py
name = input("Enter student name: ")
marks = int(input("Enter marks: "))
attendance = int(input("Enter attendance percentage: "))

if marks >= 40:
    if attendance >= 75:
        print(f"{name} passed the exam.")
    else:
        print(f"{name} failed because of low attendance.")
else:
    print(f"{name} failed because of low marks.")

Question 32 – User Input Loan Eligibility

q32_user_loan.py
name = input("Enter name: ")
age = int(input("Enter age: "))
salary = int(input("Enter salary: "))

if age >= 18:
    if salary >= 30000:
        print(f"{name}, your loan is approved.")
    else:
        print(f"{name}, your salary is too low.")
else:
    print(f"{name}, your age is not eligible.")
Part 8

Advanced Challenges (Questions 33 – 37)

Question 33 – Shopping Discount Calculator

Discount rules: 5000+ = 20%, 3000-4999 = 10%, 1000-2999 = 5%, Below 1000 = No discount.

q33_shopping_discount.py
product = input("Enter product name: ")
price = float(input("Enter price: "))
quantity = int(input("Enter quantity: "))

total = price * quantity

if total >= 5000:
    discount = total * 20 / 100
elif total >= 3000:
    discount = total * 10 / 100
elif total >= 1000:
    discount = total * 5 / 100
else:
    discount = 0

final_amount = total - discount

print(f"Product: {product}")
print(f"Total Amount: ₹{total}")
print(f"Discount: ₹{discount}")
print(f"Final Amount: ₹{final_amount}")

Question 34 – ATM Withdrawal System

Conditions: 1. Withdrawal <= balance. 2. Withdrawal must be a multiple of 500.

q34_atm_rules.py
balance = float(input("Enter your balance: "))
withdrawal = float(input("Enter withdrawal amount: "))

if withdrawal <= balance:
    if withdrawal % 500 == 0:
        balance = balance - withdrawal
        print("Withdrawal successful.")
        print(f"Remaining balance: ₹{balance}")
    else:
        print("Amount must be a multiple of 500.")
else:
    print("Insufficient balance.")

Question 35 – Electricity Bill Calculator

Rates: 0-100 units = ₹5/unit, 101-200 units = ₹7/unit, 201-300 units = ₹10/unit, Above 300 = ₹15/unit.

q35_electricity_bill.py
units = int(input("Enter electricity units: "))

if units <= 100:
    rate = 5
elif units <= 200:
    rate = 7
elif units <= 300:
    rate = 10
else:
    rate = 15

bill = units * rate

print(f"Units Consumed: {units}")
print(f"Rate: ₹{rate} per unit")
print(f"Total Bill: ₹{bill}")

Question 36 – Movie Ticket Pricing System

Pricing: Age < 18 (Normal ₹150, Premium ₹200); Age >= 18 (Normal ₹200, Premium ₹300).

q36_movie_tickets.py
name = input("Enter your name: ")
age = int(input("Enter your age: "))
ticket_type = input("Enter ticket type (normal/premium): ")

if age < 18:
    if ticket_type == "normal":
        price = 150
    else:
        price = 200
else:
    if ticket_type == "normal":
        price = 200
    else:
        price = 300

print(f"Name: {name}")
print(f"Ticket Type: {ticket_type}")
print(f"Ticket Price: ₹{price}")

Question 37 – Employee Bonus Calculator

Rules: Experience >= 5 (Salary >= 50k → 20%, else 15%); Experience < 5 (Salary >= 50k → 10%, else 5%).

q37_employee_bonus.py
name = input("Enter employee name: ")
salary = float(input("Enter salary: "))
experience = int(input("Enter years of experience: "))

if experience >= 5:
    if salary >= 50000:
        bonus = salary * 20 / 100
    else:
        bonus = salary * 15 / 100
else:
    if salary >= 50000:
        bonus = salary * 10 / 100
    else:
        bonus = salary * 5 / 100

final_salary = salary + bonus

print(f"Employee Name: {name}")
print(f"Salary: ₹{salary}")
print(f"Bonus: ₹{bonus}")
print(f"Final Salary: ₹{final_salary}")