Practice and reinforce the concepts from Lesson 10
:alarm_clock: Time: 45-60 minutes
:dart: What you'll create: Three amazing loop-powered programs including animated turtle patterns and a number rounding tool!
In this activity, you'll master the power of loops in Python! You'll create mesmerizing patterns with Turtle Graphics and build smart programs that process lists automatically. Get ready to make your computer do the repetitive work for you!
:white_check_mark: Make sure you're logged into EduBlocks
:white_check_mark: Have your lesson notes ready for reference
:white_check_mark: Remember: loops help us repeat code without typing it over and over!
:white_check_mark: Save your work every 5-10 minutes
Go to EduBlocks page and login with your Google account: https://app.edublocks.org/login
Every time you want to start a new project:
:bulb: :bulb: Pro Tip: Create all three projects at the beginning and switch between them using the Projects menu. This saves time later!
Important Notes:
- Save your work every 5 minutes (seriously, do it!)
- Keep all three project tabs open - you'll need the share links for submission
- If a pattern doesn't look right, check your loop numbers first!
Steps to Complete Your Loops Exercises
One. Exercise (Loops) 1 - Turtle Pattern Drawing :star2:
Time: 15-20 minutes
Let's create a hypnotic spinning pattern using the power of nested loops!
Step-by-Step Instructions:
- Drag the import block from the Turtle category
- Add a "define turtle" block and name it
t
- Set the speed to
10
(fast but visible)- Position your turtle:
- Drag a "pen up" block
- Add a "go to x: y:" block and set x to
-100
and y to50
- Drag a "pen down" block
- Create the main loop structure:
- Drag a "While True:" block (this creates an infinite loop!)
- Inside it, drag a "For i in range():" block and set range to
3
- Inside the For loop, add:
- A "forward" block set to
90
pixels- A "right" block set to
100
degrees- After the For loop (but still inside While):
- Add another "right" block set to
34
degreestip :dart: What's happening? The While loop keeps running forever, and each time it runs, the For loop draws a 3-sided shape. The 34-degree turn at the end rotates everything slightly, creating the spinning effect!
Your Loop Structure Should Look Like:
While True:
For i in range(3):
• Move forward 90 pixels
• Turn right 100 degrees
• Turn right 34 degrees
Time: 15-20 minutes
Transform messy decimal numbers into clean whole numbers using loops and lists!
Create your numbers list:
numbers
[17.4, 22.9, 12.34, 21.2, 77.3, 52.45, 8.2]
Show the original list:
"Before:"
numbers
variableCreate your rounding loop:
len()
block with numbers
as the inputInside the For loop:
numbers
i
round(numbers[i])
Show the transformed list:
"After:"
numbers
variable:bulb: :bulb: Why use len()? The
len()
block tells us how many items are in the list. If we have 7 numbers,len(numbers)
returns 7, so our loop runs from 0 to 6 - perfect for accessing each list item!
Helpful Block Locations:
- Use the
len()
block to get list length:
- Use the
round()
block to round numbers:
Your output should look like this:
3. Exercise (Loops) 3 - Advanced Turtle Spiral Pattern :emoji:
Time: 15-20 minutes
Create a mind-blowing spiral pattern that grows bigger with each loop iteration!
Step-by-Step Instructions:
- Set up your turtle:
- Drag the import block from the Turtle category
- Add a "define turtle" block and name it
t
- Set the speed to
0
(maximum speed - zoom zoom!)- Create the spiral structure:
- Drag a "While True:" block (infinite loop magic!)
- Inside it, drag a "For i in range():" block
- Set the range to
360
(one for each degree in a circle)- Inside the For loop, add:
- A "forward" block with
i
as the distance (not a fixed number!)- A "left" block set to
59
degreestip :emoji: Mind-Blowing Fact: The variablei
starts at 0 and increases by 1 each time the loop runs. So the turtle moves forward 0 pixels, then 1 pixel, then 2 pixels... all the way to 359 pixels! This creates the spiral effect!
Your Loop Structure:
While True:
For i in range(360):
• Move forward (i) pixels ← Notice we use the variable i!
• Turn left 59 degrees
Why 59 degrees? This creates a beautiful golden spiral pattern. Try changing it to 58 or 60 after you finish to see what happens!
Pattern not appearing?
List rounding not working?
i
as the index in numbers[i]
len(numbers)
for the rangenumbers[i] = round(numbers[i])
Spiral looks weird?
i
in the forward block, not a fixed numberReady for more? Try these advanced challenges:
Rainbow Pattern (Exercise 1):
t.color()
with different colors each iterationSmart Rounding (Exercise 2):
Double Spiral (Exercise 3):
What you're learning with blocks translates directly to Python:
while True:
(infinite loops in Python)for i in range(3):
(counting loops)len(numbers)
(getting list length)numbers[i]
(accessing list items by index)Before submitting, make sure each exercise has:
Exercise One:
Exercise 2:
Exercise 3:
When you have completed all three "Python Loops Exercises", submit them using the link below:
Important Submission Steps:
Note: You need to submit 3 project links for this activity - one for each exercise. Don't forget any!