By the end of this lesson, you will be able to:
🎯 Use if, elif, and else statements to control program flow.
🎯 Write nested conditionals.
🎯 Apply Boolean expressions and logical operators.
This lesson is all about making decisions in code. You'll learn to use if, elif, and else statements to create decision structures. You'll also explore nested conditions and logical operations (and, or, not).
Python Code
x = int(input("Enter a number: "))
if x > 0:
   print("Positive")
elif x == 0:
   print("Zero")
else:
   print("Negative")
Open Google Colab, create a new notebook, and run the examples above in new code cells.
Python Code
x = int(input("Enter a number: "))
if x > 0:
   if x > 10:
       print("Greater than 10")
   else:
       print("Between 1 and 10")
else:
   print("Zero or Negative")
Run the examples above in new code cells.
Python Code
x = 5
y = 10
if x > 0 and y > 0:
   print("Both are positive")
Run the examples above in new code cells.
🧠Answer these to test your understanding.
What does this code print if x = -3?
if x > 0:
   print("A")
elif x == 0:
   print("B")
else:
   print("C")
🔧 Instructions:
Write a program that categorizes someone’s age based on their age input:
Child: <12
Teen: 12–17
Adult: 18–64
Senior: 65+