如何在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.測試代碼效果
預期效果:
