Lesson 5: Making Decisions with if-else 🔄
Now that we know how to take user input, let's make our programs smarter by using if-else conditions! These allow our program to make decisions based on user input or other factors.
---
Example:
age = int(input("How old are you? "))
if age >= 18:
print("You are an adult!")
else:
print("You are a minor!")
---
Explanation:
1. if statement: Checks a condition. If it evaluates to True, the indented block runs.
2. else statement: Runs if the if condition is False.
3. Comparison operators (>=,
Now that we know how to take user input, let's make our programs smarter by using if-else conditions! These allow our program to make decisions based on user input or other factors.
---
Example:
age = int(input("How old are you? "))
if age >= 18:
print("You are an adult!")
else:
print("You are a minor!")
---
Explanation:
1. if statement: Checks a condition. If it evaluates to True, the indented block runs.
2. else statement: Runs if the if condition is False.
3. Comparison operators (>=,