1.注意标准库的两种导入与使用方式,建议大家采用<库名>.<函数名>的方式。
2.对前面的代码进行优化,用for,while,if,def实现:
a.画五角星
b.画同心圆
c.画太阳花
d.画五个角星
a.
>>> turtle.reset()
>>> turtle.color('yellow')
>>> turtle.fillcolor('yellow')
>>> turtle.begin_fill()
>>> for i in range(5):
turtle.forward(200)
turtle.left(144)
>>> turtle.end_fill()
b.
>>> turtle.reset()
>>> for i in range(5):
turtle.circle(20*(i+1))
turtle.up()
turtle.right(90)
turtle.forward(20)
turtle.left(90)
turtle.down()
c.
import turtle
turtle.color('red')
turtle.fillcolor('yellow')
turtle.begin_fill()
while True:
turtle.forward(200)
turtle.left(80)
if abs(turtle.pos())<1:
break
turtle.end_fill()
d.
import turtle
turtle.bgcolor('red')
turtle.color('yellow')
turtle.fillcolor('yellow')
turtle.begin_fill()
turtle.up()
turtle.goto(-200,50)
turtle.down()
for i in range(5):
turtle.forward(200)
turtle.left(144)
turtle.end_fill()
turtle.up()
turtle.left(35)
turtle.forward(300)
turtle.down()
turtle.fillcolor('yellow')
turtle.begin_fill()
for i in range(5):
turtle.forward(50)
turtle.left(144)
turtle.end_fill()
turtle.up()
turtle.right(90)
turtle.forward(100)
turtle.left(90)
turtle.down()
turtle.fillcolor('yellow')
turtle.begin_fill()
for i in range(5):
turtle.forward(50)
turtle.left(144)
turtle.end_fill()
turtle.up()
turtle.right(120)
turtle.forward(100)
turtle.left(120)
turtle.down()
turtle.fillcolor('yellow')
turtle.begin_fill()
for i in range(5):
turtle.forward(50)
turtle.left(144)
turtle.end_fill()
turtle.up()
turtle.right(150)
turtle.forward(100)
turtle.left(150)
turtle.down()
turtle.fillcolor('yellow')
turtle.begin_fill()
for i in range(5):
turtle.forward(50)
turtle.left(144)
turtle.end_fill()