A coloured star
Section 7: Drawing with the turtleLesson 7.2 · ⏱ 8 min
import turtle
t = turtle.Turtle()
t.speed(0)
colors = ["red", "orange", "gold", "green", "blue", "purple"]
for i in range(36):
t.color(colors[i % 6])
t.forward(180)
t.left(170)
🐍 Open the code in Robo Python ↗📌 Another example: a five-pointed star
We turn 144 degrees five times.
import turtle
t = turtle.Turtle()
t.color("orange")
t.pensize(3)
for i in range(5):
t.forward(180)
t.right(144)
🐍 Open the code in Robo Python ↗
✍️ Practise
Try the lesson's examples here: copy the code, change it, and click ▶ Run.
✍️ Practise here in the lesson✖ Close the labor open the lab in a new page ↗
🎯 Challenge yourself
Easy
A small red star (100).
👀 Show the solution🙈 Hide the solution
import turtle
t = turtle.Turtle()
t.color("red")
for i in range(5):
t.forward(100)
t.right(144)
🐍 Open the code in Robo Python ↗
Result: a red star.
Medium
A star whose colours change with every side.
👀 Show the solution🙈 Hide the solution
import turtle
t = turtle.Turtle()
colors = ["red", "orange", "gold", "green", "blue"]
t.pensize(4)
for i in range(5):
t.color(colors[i])
t.forward(160)
t.right(144)
🐍 Open the code in Robo Python ↗
Result: every side in a colour.
Hard
Three stars in different sizes (a star(size) function).
👀 Show the solution🙈 Hide the solution
import turtle
t = turtle.Turtle()
def star(size):
for i in range(5):
t.forward(size)
t.right(144)
t.speed(0)
for size, x in [(60, -150), (100, -40), (140, 90)]:
t.penup()
t.goto(x, 0)
t.pendown()
star(size)
🐍 Open the code in Robo Python ↗
Result: three stars getting bigger.

