Conditional Statements
Conditional Statements are used in programming to make decisions based on conditions.
They help a program choose what action to perform depending on whether a condition is True or False.
Real-Life Example
- If it is raining → take an umbrella
- Else → go outside normally
Just like this, Python programs make decisions.
Example
age = 18
if age >= 18:
print("You can vote")
else:
print("You are too young")
Output:
You can vote
Explanation
- age >= 18 → checks condition
- if → runs when condition is True
- else → runs when condition is False
Types of Conditional Statements
- if statement – checks a condition
- if-else statement – gives two choices
- if-elif-else – checks multiple conditions
- nested if – condition inside another condition
Common Beginner Mistakes
- Missing colon (:)
- Wrong indentation
- Using = instead of ==
- Writing incorrect conditions
Why Use Conditional Statements?
- Helps in decision making in programs
- Makes apps and games smarter
- Used in login systems, grading systems, and real-life applications
Real-World Uses
- ATM machines checking balance
- Login systems verifying passwords
- Games deciding win/lose
- School grading systems
➤ Key Points
Conditional statementshelp in decision-making- Based on True/False conditions
- Use if, else, elif
- Important for real-world programs
➤ Tips for Students
- Practice simple if conditions
- Always use colon (:) after if
- Maintain proper indentation
- Start with small programs