๐ Python Loops Adventure - Day 4
Make your code repeat like magic! Learn loops! ๐ช
1 Why Loops? ๐ค
๐กProblem: Printing "Hello" 10 times without loops = 10 lines of code!
โจMagic! The loop repeats the indented code automatically! Change 3 to 10 and watch!
2 Your First For Loop ๐
๐Learn: A for loop repeats code for each number in a range!
Start
โ
Do action
โ
Repeat
โ
Done!
๐ขNotice: number changed from 0 to 4! Python starts counting at 0.
3 Understanding Range ๐
๐ฏLearn: range() creates sequences of numbers!
Range Examples:
range(5) โ 0, 1, 2, 3, 4
range(1, 6) โ 1, 2, 3, 4, 5
range(0, 10, 2) โ 0, 2, 4, 6, 8
range(10, 0, -1) โ 10, 9, 8, ..., 1
๐งชTry: range(10, 0, -1) to count backwards from 10 to 1!
4 Multiplication Table! โ๏ธ
๐งฎBuild: Create any multiplication table with loops!
๐Try: Enter 7 for the 7 times table! Test with 3, 9, or 12!
5 Pattern Maker! ๐จ
๐บChallenge: Create cool patterns with loops!
๐กTry: Make patterns with emojis! Use "๐" * i or "โค๏ธ" * i
6 Number Guesser Game! ๐ฎ
๐ฏFinal Project: Build a guessing game with 3 attempts!
๐Upgrades:
- Change secret to a random number
- Give 5 attempts instead of 3
- Make range 1-100 for hard mode
- Add a score counter
๐ You're a Loop Master! ๐
You can make code REPEAT automatically! ๐
You learned: for loops, range(), patterns, and games!