Reputation: 412
I am drawing a heptagon using this code:
tegan.setheading(0);
for i in range (7):
tegan.right(51.43)
tegan.forward(100)
However, this code always draws the shape with a flat edge at the top and I want the point at the top. What am I doing wrong?
Upvotes: 0
Views: 1861
Reputation: 41895
Alternatively, you can simply do:
import turtle
turtle.circle(-116, steps=7)
turtle.done()
Upvotes: 1
Reputation: 261860
To make an heptagon, you need to rotate 360°/7 each step. To have the point up, you rotate only half on the first step.
One trick to do this is to rotate in one direction (here left) half the angle, and then proceed in the other direction with the full angle seven times. Another possibility is to write a condition in the loop for the first step, or split the code in two.
import turtle
angle = 360/7
turtle.left(angle/2)
for i in range(7):
turtle.right(angle)
turtle.forward(100)
Upvotes: 2