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
Release: 2024-03-01 16:37:31
forward
940 people have browsed it

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()
Copy after login

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!

Related labels:
source:lsjlt.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template