🔄 Lesson 5: Loops (Repetition)
⏱️ Estimated time: 25 minutes | Difficulty: Beginner
Automation
Loops allow you to run the same code multiple times, which is essential for processing lists of data or performing repetitive calculations.
⏱️ Estimated time: 25 minutes | Difficulty: Beginner
Loops allow you to run the same code multiple times, which is essential for processing lists of data or performing repetitive calculations.
An if statement lets your program make decisions. It runs different code based on conditions.
🌧️ If it's raining: Take an umbrella
☀️ Else (if it's not raining): Don't take an umbrella
age = 18
if age >= 18:
print("You can vote!")
print("Welcome to voting!")
Output:
You can vote!
Welcome to voting!
These are used in if statements to compare values:
== Equal
if name == "Alice":
print("Hi Alice!")
!= Not Equal
if name != "Bob":
print("You're not Bob!")
> Greater
if score > 50:
print("You passed!")
< Less
if age < 13:
print("You're a kid!")
>= Greater or Equal
if score >= 90:
print("Grade: A")
<= Less or Equal
if age <= 12:
print("Child price")
age = 15
if age >= 18:
print("You can vote!")
else:
print("You can't vote yet.")
Output:
You can't vote yet.
score = 85
if score >= 90:
print("Grade: A")
elif score >= 80:
print("Grade: B")
elif score >= 70:
print("Grade: C")
else:
print("Grade: F")
Output:
Grade: B
age = 25
has_license = True
# AND: Both must be true
if age >= 18 and has_license:
print("You can drive!")
# OR: At least one must be true
if age < 13 or age > 65:
print("Special pricing available")
❓ What will this print?
x = 10
if x >
5:
print("Big")
❓ What operator checks "not equal"?
❓ When do you use "elif"?
Write a program that:
Hint: Use input() to get the user's age