Answer: Turtle Challenge #41

Here’s what the code from Turtle Challenge #41 draws. This picture was made by running the code for real.

The drawing made by turtle challenge 41.
What the turtle drew.

The answers

How many sides will the shape have? 9 sides. The loop runs 9 times, and each time the turtle draws one side.

What is the shape called? A nonagon.

Does the turtle end up back where it started? Yes! It turns 9 × 40 = 360 degrees in total, which is one full turn, so it finishes exactly where it began, facing the same way.

How the code works

The turtle walks forward 60 steps and turns left 40 degrees, 9 times. Turning 360 ÷ 9 = 40 degrees at each corner closes the shape perfectly.

import turtle

t = turtle.Turtle()
t.speed(0)
t.pensize(5)
t.pencolor("mediumpurple")

for side in range(9):
    t.forward(60)
    t.left(40)

t.hideturtle()
turtle.done()

Try it: Change both numbers so the turtle draws a shape with 6 sides. (Hint: 360 ÷ sides.)