如何在Python上画一个九角星
1.准备:Python 3.7和win10系统
2.打开Python IDLE界面,然后开始输入代码
参考代码:
import turtle
turtle.pensize(2)
turtle.pencolor("yellow")
turtle.fillcolor("red")
turtle.begin_fill()
for i in range(9):
turtle.forward(100)
turtle.pencolor("yellow")
turtle.fillcolor("red")
turtle.begin_fill()
for i in range(9):
turtle.forward(100)
turtle.right(160)
turtle.forward(100)
turtle.left(120)
turtle.end_fill()
turtle.left(120)
turtle.end_fill()
turtle.hideturtle()
turtle.done()
turtle.done()
![](https://i-blog.csdnimg.cn/blog_migrate/d9f0feed1e78d0b1624b8ff4155a6791.png)
3.测试代码效果
预期效果:
![](https://i-blog.csdnimg.cn/blog_migrate/fdbeec62fb2090afdcd40e5e393d1f6f.png)