- Use nested loops to create complex patterns
- Understand rotation to create spiral/circular patterns
- Learn the relationship between sides and angles (360/sides)
- Introduce while loops as an alternative to for loops
- Apply mathematical thinking to visual patterns
- Patterns are made by repeating shapes while rotating
- We can use math to figure out angles: 360 ÷ number of sides
- Nested loops mean "a loop inside a loop" - outer loop rotates, inner loop draws
- While loops repeat "while" a condition is true (different from "repeat N times")
- for loop: "Do this exactly N times" → for i in range(10):
- while loop: "Do this while condition is true" → while score < 10:
- Example: Game keeps going WHILE player has lives
- Example: Pattern continues WHILE rotation < 360 degrees
- Week 7: We drew shapes with functions
- Week 5: We used for loops for training rounds
- Week 8: We combine loops + rotation to make patterns
- Scratch equivalent: "Repeat until" (while) vs "Repeat 10" (for)
- Review: "How do we draw a square?" (4 sides, 90-degree turns)
- Question: "What angle do we need for a hexagon?" (360÷6 = 60 degrees)
- Quick demo: Run week08.py and observe the patterns
Part A: Angle mathematics (5 min) Draw on board:
- Triangle: 3 sides → turn 360÷3 = 120 degrees
- Square: 4 sides → turn 360÷4 = 90 degrees
- Pentagon: 5 sides → turn 360÷5 = 72 degrees
- Hexagon: 6 sides → turn 360÷6 = 60 degrees
Part B: While loops (5 min) Show comparison:
# For loop: Exact count
for i in range(5):
print("Round", i+1)
# While loop: Until condition
rounds = 0
while rounds < 5:
print("Round", rounds+1)
rounds = rounds + 1When to use each:
- Use for when you know how many times
- Use while when you repeat until something happens
Part C: Nested loops for patterns (5 min)
for _ in range(6): # Outer: repeat 6 times
for _ in range(4): # Inner: draw a square
t.forward(60)
t.right(90)
t.right(60) # Rotate before next squarePart A: Simple polygon (10 min)
sides = 6 # Try changing this!
step = 80
turn = 360 / sides # Math calculates the angle
for _ in range(sides):
t.forward(step)
t.right(turn)- Experiment together: Change sides to 3, 4, 5, 8
- Observe: The angle changes automatically
- Question: "What happens with sides = 360?" (Almost a circle!)
Part B: Pattern with rotation (10 min)
for _ in range(18): # Outer loop: repeat pattern 18 times
for _ in range(4): # Inner loop: draw one square
t.forward(60)
t.right(90)
t.right(20) # Rotate 20 degrees before next square- Draw diagram: Show how each square rotates
- Math: 18 squares × 20 degrees = 360 degrees (full circle)
- Ask: "What if we used 10 degrees?" (Need 36 squares for full circle)
Part C: While loop alternative (5 min) Show how we could use while instead:
rotation = 0
while rotation < 360:
for _ in range(4):
t.forward(60)
t.right(90)
t.right(20)
rotation = rotation + 20Same result, different approach!
Task A: Run and observe
- Run the program
- Identify the two patterns
- Count how many shapes in the circular pattern
Task B: Modifications (from student_tasks.md)
- Change
sidesto 8 and observe - Change the outer loop range to 12 (instead of 18)
- Change rotation angle from 20 to 10
- Change square size from 60 to 40
Task C: Creative challenges
- Create a pattern with triangles instead of squares
- Make a pattern that uses both squares and hexagons
- Create a spiral pattern using while loop with increasing size
- Try making a "flower" pattern (circles arranged in circle)
Challenge extension:
# Spiral with increasing size
size = 10
while size < 200:
t.forward(size)
t.right(90)
size = size + 5Students explain:
- "How do we calculate the turn angle for any shape?"
- "What's the difference between for and while loops?"
- "What does the outer loop do vs the inner loop?"
- "How would you create a 10-pointed star pattern?"
-
Wrong angle calculation
sides = 5 turn = 360 * sides # Wrong! Should be 360 / sides
- Shows: Weird shape that doesn't close
- Fix: Use division, not multiplication
-
Infinite while loop
count = 0 while count < 10: t.forward(50) # Forgot to increment count!
- Shows: Loop never ends, program freezes
- Fix: Add count = count + 1 inside loop
-
Nested loop confusion
for _ in range(18): t.forward(60) # Moved out of inner loop for _ in range(4): t.right(90)
- Shows: Broken pattern
- Fix: Keep shape-drawing code in inner loop
-
Speed too slow
t.speed(1) # Very slow # With complex patterns
- Shows: Takes forever to complete
- Fix: Use t.speed(0) for instant drawing
- Student can explain the 360/sides formula
- Student can modify pattern parameters and predict results
- Student can explain difference between for and while loops
- Student can identify outer vs inner loops in nested structure
- Student creates at least one custom pattern
For students who need support:
- Start with just the simple polygon (first part)
- Provide pre-calculated angles (don't worry about formula yet)
- Use only for loops (skip while loops initially)
- Limit to 2 patterns total
For advanced students:
- Create 3+ different patterns in one program
- Experiment with color changes in loops (t.color())
- Create patterns with 3 nested loops
- Use while loop with user input to control pattern
- Research and implement Spirograph-style patterns
- Thonny IDE
- week08.py file
- Calculator (for angle calculations)
- Optional: Compass and protractor for visual demo
- Optional: Printout of angle formula table
- Nested loop: Loop inside another loop
- Outer loop: The loop that contains another loop
- Inner loop: The loop inside another loop
- Rotation: Turning by an angle
- While loop: Loop that continues while condition is true
- Iteration: One pass through a loop
- Angles and degrees (360° in full rotation)
- Division for equal distribution
- Multiplication for counting rotations
- Geometry: Regular polygons and their properties
- Create a pattern using triangles (3 sides, 120° turns)
- Make a pattern that uses exactly 10 shapes in a circle
- Draw a spiral that grows outward
- Use a while loop to draw shapes until they reach screen edge