Conditional statements let your program make decisions — running certain code only when a condition is True. The if statement is the most basic form of decision-making.
marks = 85
if marks >= 40:
print("Result: Pass")The else block runs when the if condition is False, giving your program two possible paths.
marks = 32
if marks >= 40:
print("Result: Pass")
else:
print("Result: Fail")A nested if is an if statement placed inside another if or else block — useful when you need to check a second condition only after the first one is satisfied.
marks = 92
if marks >= 40:
print("Result: Pass")
if marks >= 90:
print("Grade: A+ (Distinction)")
else:
print("Grade: B")
else:
print("Result: Fail")When you have multiple conditions to check in sequence, elif (else-if) is cleaner than multiple nested if statements.
marks = 76
if marks >= 90:
grade = "A+"
elif marks >= 75:
grade = "A"
elif marks >= 60:
grade = "B"
elif marks >= 40:
grade = "C"
else:
grade = "Fail"
print("Grade:", grade)Introduced in Python 3.10, match-case is Python's version of a switch statement — useful when comparing one variable against several fixed values.
day = "MON"
match day:
case "MON":
print("Digital Marketing Class")
case "WED":
print("SEO Class")
case "FRI":
print("Google Ads Class")
case _:
print("No class scheduled")Before writing code, it helps to visualize the decision-making process as a flowchart. This builds logical thinking — a core skill for every programmer and data analyst.
Figure 5.1 — Basic if-else decision flow: the program checks a condition, then follows exactly one of two paths before continuing.
Basic (5 Questions)
1. Write a program to check if a number is positive or negative.
2. Write a program to check if a person is eligible to vote (age >= 18).
3. Check if a given number is even or odd using if-else.
4. Write a program that checks if a student passed or failed given their marks.
5. Check if a year is a leap year using basic if conditions (divisible by 4).
Intermediate (5 Questions)
1. Write a grading program using elif that assigns A+/A/B/C/Fail based on marks.
2. Check if a number is divisible by both 3 and 5 using nested if.
3. Write a program using match-case to print a message based on a day of the week.
4. Build a simple login checker that verifies both username and password using nested if.
5. Write a program to find the largest of 3 numbers using elif.
Advanced (5 Questions)
1. Build a BMI Calculator that categorizes a person as Underweight/Normal/Overweight/Obese using elif.
2. Draw a flowchart AND write the code for a simple 'course fee discount' system (student gets 10% off if fee > 10000).
3. Write a program that validates a password (must be 8+ characters AND contain at least 1 number) using nested conditions.
4. Create a simple traffic-light simulator using match-case (Red = Stop, Yellow = Get Ready, Green = Go).
5. Build a 'Loan Eligibility Checker' using nested if that checks income, age, and credit score together.
Q1. What does Python use to define a block of code?
Q2. Which keyword checks multiple conditions in sequence?
Q3. What is a nested if?
Q4. Which Python version introduced match-case?
Q5. What does the underscore _ represent in match-case?
Assignment: Student Result & Grading System
Expected Output: A complete grading script that correctly classifies any input marks into the right grade band and adds a distinction remark where applicable.
Use this space to write down key points, doubts, and your own examples from today's session.