Home >Backend Development >Python Tutorial >How to draw a five-pointed star using for loop in Python

How to draw a five-pointed star using for loop in Python

WBOY
WBOYforward
2024-03-01 16:37:31932browse

How to draw a five-pointed star using for loop in Python

To use a for loop to draw a five-pointed star, you can use 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()

Run the above code and a five-pointed star will be drawn on the canvas.

The above is the detailed content of How to draw a five-pointed star using for loop in Python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:lsjlt.com. If there is any infringement, please contact admin@php.cn delete