🐍 Learn Python Basics
🔄 Loops
🚀 What is a Loop?
Loops are Like Magic Spells! 🪄
Loop tells the computer to repeat something over and over again!
Imagine you have a pet parrot 🦜 that keeps saying "Hello!"
Instead of telling it 5 times, you can use a **loop**!
🤖 Python Makes Repeating Easy!
Instead of printing "hello" 5 times, we can use a loop:
print("hello") print("hello") print("hello") print("hello") print("hello")
for number in range(0, 4): print("hello")
🎉 This will print hello 5 times automatically!
🍪 Another Fun Example: Eating Cookies!
Imagine you have 3 cookies 🍪🍪🍪 and you want to eat them **one by one**:
for cookie in range(0, 3): print("Mmm... eating cookie number", cookie)
👉 Output:
Mmm... eating cookie number 1 Mmm... eating cookie number 2 Mmm... eating cookie number 3
💡 Why Use Loops?
- ✅ **Repeat tasks easily** (like clapping 👏👏👏)
- ✅ **Save time** instead of writing the same thing many times
- ✅ **Make games and animations fun! 🎮**
Click the button below to play a game where you help a **bunny** 🐰 hop using loops!