Python by Projects › Turtle Art Studio
Exercises: Turtle Art Studio
You will predict, trace, repair, and design turtle art. Keep headless calculations and reports in this notebook. Turtle commands belong only in the named scripts in assets/.
For a script exercise, open the named starter, delete its small starter rectangle, author the requested program, save it, and run the named script from a terminal in this unit folder. Close the turtle window when you finish.
Exercise 1
Turn assets/ex1_square_studio.py into a square studio. Keep import turtle. Author meaningful variables for straight_sides, side_length, and angle = 360 / straight_sides. Choose a color and starting pen size, then use for side_number in range(straight_sides) to draw the square. Inside the loop, make side_number control the pen with turtle.pensize(side_number + 1). Include one comment that explains the loop, finish with turtle.done(), and run the script.
In the blank cell, author the same three numeric variables and use an f-string to print a report in this exact pattern: 4 sides of 80 steps.
Real program
The solution shows how to ask for the number of straight sides before computing and printing the report.
How this is checked: You check this one yourself, against the list below. The turtle drawing is checked from the moves your program makes.
The site cannot check this one. Run your program, then tick each item below when your work does it.
Exercise 2
Complete this range() prediction table. Write every counter value in order. Do the predictions without running turtle code.
| Loop | Number of trips | Counter values |
|---|---|---|
range(3) |
___ | ___ |
range(5) |
___ | ___ |
range(8) |
___ | ___ |
Then use the blank cell to author n = 7, angle = 360 / n, and a for side_number in range(n) loop. Inside the loop, print side_number + 1 and angle. Run the cell and explain in a comment why the angle is a decimal near 51.428571 and why the last counter value is 6. Do not use round() in your code.
Real program
For the program, the solution shows how to ask for n before computing and printing the loop values.
How this is checked: Checked by tests that run your code.
Exercise 3
This headless plan is meant to stand for a four-sided drawing, but the loop makes the wrong number of sides. Change one number so the loop takes four trips. Then change the fixed side length so side_number is used in an expression: the four planned lengths must be 50, 60, 70, and 80. Keep the counter name and add a comment that explains both repairs.
How this is checked: You check this one yourself, against the list below.
The site cannot check this one. Run your program, then tick each item below when your work does it.
Exercise 4
Read the nested loops in assets/l3_spirograph.py. Complete the trace below before running the script.
| Question | Your prediction |
|---|---|
| How many trips does the outer loop take? | ___ |
| How many trips does the inner loop take during one outer trip? | ___ |
| How many straight sides are drawn in the complete design? | ___ |
| Which loop rotates between whole polygons? | ___ |
Describe why the inner loop must finish before the next polygon begins. Then author a headless nested-loop plan in the blank cell: the outer loop uses shape_number with range(3), the inner loop uses side_number with range(4), and both counters must appear in expressions that create shape_label and side_label. Print both labels inside the inner loop.
Real program
For the program, the solution shows how to ask for the shape and side counts before computing and printing the labels.
How this is checked: You check this one yourself, against the list below. The turtle drawing is checked from the moves your program makes.
The site cannot check this one. Run your program, then tick each item below when your work does it.
Exercise 5
This is your flagship build: you will author a complete turtle program, not edit the finished lesson example.
Turn assets/ex5_polygon_studio.py into a complete seven-sided polygon program. Keep import turtle; author n = 7, your own side_length, and angle = 360 / n. Author pen setup with color, pensize, penup, a move, and pendown. Draw the closed polygon with for side_number in range(n): set turtle.pensize(side_number + 1), move forward, and turn right by angle. Add a comment naming the expected shape, finish with turtle.done(), save, and run the script.
In the blank headless cell, author the numeric parts again. Print angle, and use the same loop to print each side_number and side_number + 1. Also author an f-string that reports the number of sides and your side length. In a final comment, explain why using 51 degrees instead of 360 / 7 would stop the turtle from returning to its starting direction. Do not use round() in your code.
Real program
The solution shows how to ask for n before computing and printing the polygon report.
How this is checked: You check this one yourself, against the list below. The turtle drawing is checked from the moves your program makes.
The site cannot check this one. Run your program, then tick each item below when your work does it.
Exercise 6
The plan below should make 10 four-sided shapes. Two loop numbers are wrong. Repair both numbers. Inside the outer loop, author shape_label = shape_number + 1. Inside the inner loop, author side_label = side_number + 1. Print both labels from inside the inner loop. Then write a comment beside each loop saying what it controls.
More Practice
Use these after the in-class path to build speed and independence. They are core exercises, not Challenges.
How this is checked: Checked by tests that run your code.
Exercise 7
Turn assets/ex7_triangle_trail.py into a complete triangle program. Author meaningful variables for three sides, a side length, and angle = 360 / side_count. Choose a color, lift and lower the pen before drawing, and choose a starting pen size. Use for side_number in range(side_count); inside it, use turtle.pensize(side_number + 2), then move and turn. Add a useful comment, finish with turtle.done(), and run the script. In the blank cell, author an f-string that reports your side count, side length, and color.
Real program
The solution shows how to ask for the color name before printing the triangle report.
How this is checked: You check this one yourself, against the list below. The turtle drawing is checked from the moves your program makes.
The site cannot check this one. Run your program, then tick each item below when your work does it.
Exercise 8
Turn assets/ex8_heptagon_steps.py into a second seven-sided design. Author n = 7, a different side length, and angle = 360 / n. Choose a different color from Exercise 5, use turtle.penup(), then turtle.backward(40) — it is forward in reverse — and turtle.pendown() before drawing, and choose a starting pen size. Draw with for side_number in range(n), making the counter control turtle.pensize(side_number + 2). Add a comment that predicts all seven counter values and notes that angle is a float, finish with turtle.done(), and run the script.
How this is checked: You check this one yourself, against the list below. The turtle drawing is checked from the moves your program makes.
The site cannot check this one. Run your program, then tick each item below when your work does it.
Exercise 9
Turn assets/ex9_square_ring.py into a ring of four squares. Author turtle setup with a color and pensize. Use an outer for shape_number in range(4) loop and an inner for side_number in range(4) loop. Inside the outer loop, make shape_number set a pen size with turtle.pensize(shape_number + 1). Inside the inner loop, make side_number create side_label = side_number + 1, then draw one side and turn 90 degrees. After each complete square, lift the pen, move forward 120 steps, turn right 90 degrees, and lower the pen before the next square. Add comments that distinguish the two loops, finish with turtle.done(), and run the script.
Real program
See the solution, which asks for the shape and side counts and prints the result with print(drawn_sides, travel_moves).
How this is checked: You check this one yourself, against the list below. The turtle drawing is checked from the moves your program makes.
The site cannot check this one. Run your program, then tick each item below when your work does it.
Exercise 10
Author a headless studio schedule in the blank cell—no turtle import or turtle commands. Set shape_count = 3 and side_count = 5. Use nested for loops with shape_number and side_number. Inside the inner loop, author stroke_number = shape_number * side_count + side_number + 1 and print an f-string in this pattern: shape 1, side 1, stroke 1. Add one comment explaining why the final stroke number is 15.
Real program
The solution shows how to ask for shape_count and side_count before computing and printing the schedule.
How this is checked: Checked by tests that run your code.
Challenge
Try these after the ten core exercises.
Challenge 1
A five-point star uses five equal moves, but it turns farther than a regular five-sided polygon. Plan star parameters using n = 5, your own side_length, and angle = 720 / 5. Predict the counter values. Then explain how this larger turn angle changes the path. Keep the plan in the blank headless cell.
How this is checked: You check this one yourself, against the list below.
The site cannot check this one. Run your program, then tick each item below when your work does it.
Challenge 2
Plan a rainbow rosette (a ring of colored shapes) inspired by assets/l3_spirograph.py. Choose six literal color names. Write six separate color-change commands, one per line, such as turtle.color("red"). On paper, mark where each command belongs as the outer loop builds the picture. Describe the order of the colors and the pattern you expect. Do not run turtle code in this notebook.
Your rainbow plan:
Expected pattern: ___
How this is checked: You check this one yourself, against the list below. The turtle drawing is checked from the moves your program makes.
The site cannot check this one. Run your program, then tick each item below when your work does it.