Draw Five-Pointed Star with Python

You can draw a pentagon using a for loop with the following code.

import turtle

# 创建画布和画笔
t = turtle.Turtle()
s = turtle.Screen()

# 设置画笔的颜色和大小
t.pensize(2)
t.pencolor("black")

# 循环画五角星
for i in range(5):
    t.forward(100)
    t.right(144)

# 隐藏画笔
t.hideturtle()

# 显示画布
s.mainloop()

Running the above code will draw a pentagram on the canvas.

bannerAds