条件、循环、函数定义 练习
画五角星
import turtle
turtle.bgcolor('red')
turtle.color('yellow')
turtle.fillcolor('yellow')
turtle.begin_fill()
for i in range(5):
turtle.forward(80)
turtle.right(144)
turtle.end_fill()
画同心圆
import turtle
for i in range(10):
turtle.up()
turtle.goto(0,-20*(i+1))
turtle.down()
turtle.begin_fill()
turtle.circle(20*(i+1))
turtle.write(10-i)
画太阳花
import turtle
turtle.color("red")
turtle.pencolor('yellow')
turtle.pensize(3)
turtle.begin_fill()
while True:
turtle.forward(200)
turtle.left(170)
if (abs(turtle.pos()))<1:
break
turtle.end_fill()
画五个角星
import turtle
turtle.bgcolor('red')
turtle.color('yellow')
turtle.fillcolor('yellow')
def mygoto(x,y):
turtle.up()
turtle.goto(x,y)
turtle.down()
turtle.begin_fill()
mygoto(-250,200)
for i in range(5):
turtle.forward(60)
turtle.right(144)
turtle.end_fill()
turtle.begin_fill()
mygoto(-150,270)
for i in range(5):
turtle.forward(25)
turtle.right(144)
turtle.end_fill()
turtle.begin_fill()
mygoto(-130,220)
for i in range(5):
turtle.forward(25)
turtle.right(144)
turtle.end_fill()
turtle.begin_fill()
mygoto(-110,150)
turtle.left(60)
for i in range(5):
turtle.forward(25)
turtle.right(144)
turtle.end_fill()
turtle.begin_fill()
mygoto(-160,108)
turtle.left(80)
for i in range(5):
turtle.forward(25)
turtle.right(144)
turtle.end_fill()