Decision Making in Python for Beginners (CBSE Class 11-12)
Introduction to Decision Making in Python
Welcome, CBSE Class 11-12 students! Decision making in Python is like giving your computer a brain to make choices. It’s about telling Python, “Bhai, agar yeh condition true hai, toh yeh kar, nahi toh woh kar!” This is a key topic for your CBSE exams and helps you write smart programs. Let’s learn it step-by-step!
Why Learn This? : Used in games, apps, and projects—like checking if a student passed or failed.
Keywords to Remember: If statement, if-else, elif, nested if, Python for CBSE.
1. If Statement in Python for Beginners
What is It?: The if statement checks a condition. If it’s true, the code inside runs. Think of it as “agar” in Hindi!
Syntax:
if condition: # Code to run if true
Example:
age = 18 if age >= 18: print("You can vote in elections!
Output:
You can vote in elections!
Tip: Always use a colon : and indent the code (4 spaces).
2. If-Else Statement for CBSE Class 10
What is It?: Adds an “else” part. If the condition is false, else code runs. It’s like “agar nahi toh”!
Syntax:
if condition: # Code if true else: # Code if false
Example:
marks = 35 if marks >= 40: print("Pass your CBSE exam!") else: print("Sorry, try again next time!")
Output:
Sorry, try again next time!
Real-Life Example: If it’s hot (>30°C), print “Drink water!” else print “Weather is cool!”
3. Elif Statement in Python for CBSE Class 11-12
What is It?: Short for “else if,” it checks multiple conditions one by one. Perfect for grading systems!
Syntax:
if condition1: # Code if true elif condition2: # Code if true else: # Code if all false
Example:
score = 85 if score >= 90: print("A+ Grade in CBSE!") elif score >= 70: print("A Grade—Well done!") else: print("B Grade—Keep practicing!")
Output:
A Grade—Well done!
Tip: Use “elif” when you have more than two options, like marks or weather levels.
4. Nested If Statement for CBSE Class 11-12
What is It?: An “if” inside another “if” to check more conditions. It’s like a decision inside a decision!
Syntax:
if condition1: if condition2: # Code if both true
Example:
age = 20 if age >= 18: if age <= 25: print("You are a young voter!") else: print("Age not in range!")
Output:
You are a young voter!
Real-Life Example: If it’s a holiday and weather is good, print “Go for a picnic!”
Exercises for Python Decision Making (CBSE Practice)
Question 1: Write a program to check if a number is positive. If yes, print “Positive!” else print “Negative!”
Question 2: Create a program to check attendance. If >75%, print “Eligible for exams!” else print “Attend more classes!”
Question 3: Make a weather program. If temperature >30, print “Hot day!” elif 20-30, print “Pleasant!” else print “Cold!”
Solution (Try First!):
Question 1
# Question 1 num = 5 if num > 0: print("Positive!") else: print("Negative!")
Question 2
# Question 2 attendance = 80 if attendance > 75: print("Eligible for exams!") else: print("Attend more classes!")
Question 3
# Question 3 temp = 25 if temp > 30: print("Hot day!") elif temp >= 20: print("Pleasant!") else: print("Cold!")
CBSE Exam Tips:
Focus on if and if-else—simple programs like age or marks check.
Practice elif and nested if for complex problems (e.g., grading or eligibility).
Common Mistakes:
Forget colon : after if.
Wrong indentation—use 4 spaces.
Frequently Asked Questions (FAQ)
What is an if statement in Python?
It’s a way to run code only if a condition is true.
How to use if-else in CBSE projects?
Use it to handle two outcomes, like pass/fail.
Why nested if is hard?
It has multiple levels—start with simple ones!