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).
age = 20
if age >= 18:
print("You are eligible to vote.")
else:
print("You are not eligible to vote.")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).
marks = 75
if marks >= 40:
print("You passed the exam.")
else:
print("You failed the exam.")You passed the exam.
Question 3 – Even or Odd
Create a variable number = 12. Check whether the number is even or odd.
number = 12
if number % 2 == 0:
print("The number is even.")
else:
print("The number is odd.")The number is even.
Question 4 – Positive, Negative or Zero
Create a variable number = -10. Check whether the number is positive, negative or zero.
number = -10
if number > 0:
print("The number is positive.")
elif number < 0:
print("The number is negative.")
else:
print("The number is zero.")The number is negative.
Question 5 – Password Check
Create a variable password = "python123". Check whether the password is correct.
password = "python123"
if password == "python123":
print("Login successful.")
else:
print("Wrong password.")Login successful.
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.
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")Grade A
Question 7 – Age Category
Create age = 25. Categories: 0-12 Child, 13-19 Teenager, 20-59 Adult, 60+ Senior Citizen.
age = 25
if age <= 12:
print("Child")
elif age <= 19:
print("Teenager")
elif age <= 59:
print("Adult")
else:
print("Senior Citizen")Adult
Question 8 – Temperature Classification
Create temperature = 35. Above 35 Very Hot, 25-35 Hot, 15-24 Normal, Below 15 Cold.
temperature = 35
if temperature > 35:
print("Very Hot")
elif temperature >= 25:
print("Hot")
elif temperature >= 15:
print("Normal")
else:
print("Cold")Hot
Question 9 – Day Checker
Create day = 3. Display day name according to number 1 to 7.
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")Wednesday
Question 10 – Salary Category
Create salary = 35000. 50000+ High, 30000-49999 Good, 20000-29999 Average, Below 20000 Low.
salary = 35000
if salary >= 50000:
print("High Salary")
elif salary >= 30000:
print("Good Salary")
elif salary >= 20000:
print("Average Salary")
else:
print("Low Salary")Good Salary
Nested If Statements (Questions 11 – 14)
Question 11 – Nested Login System
Create username = "admin", password = "1234". Check credentials using nested if.
username = "admin"
password = "1234"
if username == "admin":
if password == "1234":
print("Login successful.")
else:
print("Wrong password.")
else:
print("Invalid username.")Login successful.
Question 12 – Driving Eligibility
Create age = 22, has_license = True. Check eligibility using nested if.
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.")You can drive.
Question 13 – Student Result (Marks + Attendance)
Create marks = 75, attendance = 80. Marks >= 40 and Attendance >= 75 required.
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.")You passed the exam.
Question 14 – Loan Eligibility
Create age = 25, salary = 40000. Age >= 18 and Salary >= 30000 required.
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.")Loan approved.
F-String Formatting (Questions 15 – 19)
Question 15 – Personal Information
Create name = "Gagan", age = 24. Print using f-string.
name = "Gagan"
age = 24
print(f"My name is {name} and I am {age} years old.")My name is Gagan and I am 24 years old.
Question 16 – Student Information
Create name = "Rahul", marks = 85. Print using f-string.
name = "Rahul"
marks = 85
print(f"{name} scored {marks} marks.")Rahul scored 85 marks.
Question 17 – Product Information
Create product = "Laptop", price = 55000. Print using f-string.
product = "Laptop"
price = 55000
print(f"{product} costs ₹{price}.")Laptop costs ₹55000.
Question 18 – Grade with F-String
Calculate grade for name = "Gagan", marks = 85 and display with f-string.
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}.")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.
name = "Gagan"
age = 24
if age >= 18:
print(f"{name} is eligible to vote.")
else:
print(f"{name} is not eligible to vote.")Gagan is eligible to vote.
User Input Basics (Questions 20 – 25)
Question 20 – Name and Age Input
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
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
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
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
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
password = input("Enter password: ")
if password == "python123":
print("Login successful.")
else:
print("Wrong password.")User Input + Elif (Questions 26 – 28)
Question 26 – User Input Grade Calculator
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
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
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}")User Input + Nested If (Questions 29 – 32)
Question 29 – User Input Login System
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
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
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
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.")Advanced Challenges (Questions 33 – 37)
Question 33 – Shopping Discount Calculator
Discount rules: 5000+ = 20%, 3000-4999 = 10%, 1000-2999 = 5%, Below 1000 = No discount.
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.
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.
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).
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%).
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}")