如何在Python上画个九角星
如何在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()
3.测试代码效果
预期效果: