Conditional Statements in
Python
Interactive Class Session
Real-Life Analogy
• Example:
• "If it's raining, I’ll take an umbrella. Else, I’ll go
without it."
• Conditional logic is used in daily life, and in
programming too!
What Are Conditional Statements?
• if: Checks the first condition
• elif: Checks another condition if previous ones
fail
• else: Executes when no above conditions are
true
Syntax of Conditionals
• if condition:
• # code block
• elif another_condition:
• # another block
• else:
• # fallback block
Example: Basic if
• x = 10
• if x > 5:
• print('x is greater than 5')
Example: if-else
• age = 16
• if age >= 18:
• print('You can vote')
• else:
• print('Too young to vote')
Example: if-elif-else
• marks = 75
• if marks >= 90:
• print('Grade: A')
• elif marks >= 60:
• print('Grade: B')
• else:
• print('Grade: C')
Using Logical Operators
• temperature = 30
• humidity = 70
• if temperature > 25 and humidity > 60:
• print('It feels hot and humid!')
Practice Questions
• 1. Check if a number is positive, negative, or
zero
• 2. Check if a year is a leap year
• 3. Grade calculator
• 4. Classify age as child, adult, or senior
Summary
• - Use if, elif, else for decision-making
• - Combine with logical operators for more
power
• - Indentation is crucial in Python!

Conditional Statements Python for basics

  • 1.
  • 2.
    Real-Life Analogy • Example: •"If it's raining, I’ll take an umbrella. Else, I’ll go without it." • Conditional logic is used in daily life, and in programming too!
  • 3.
    What Are ConditionalStatements? • if: Checks the first condition • elif: Checks another condition if previous ones fail • else: Executes when no above conditions are true
  • 4.
    Syntax of Conditionals •if condition: • # code block • elif another_condition: • # another block • else: • # fallback block
  • 5.
    Example: Basic if •x = 10 • if x > 5: • print('x is greater than 5')
  • 6.
    Example: if-else • age= 16 • if age >= 18: • print('You can vote') • else: • print('Too young to vote')
  • 7.
    Example: if-elif-else • marks= 75 • if marks >= 90: • print('Grade: A') • elif marks >= 60: • print('Grade: B') • else: • print('Grade: C')
  • 8.
    Using Logical Operators •temperature = 30 • humidity = 70 • if temperature > 25 and humidity > 60: • print('It feels hot and humid!')
  • 9.
    Practice Questions • 1.Check if a number is positive, negative, or zero • 2. Check if a year is a leap year • 3. Grade calculator • 4. Classify age as child, adult, or senior
  • 10.
    Summary • - Useif, elif, else for decision-making • - Combine with logical operators for more power • - Indentation is crucial in Python!