1、注意标准库的两种导入与使用方式,建议大家采用<库名>.<函数名>的方式。
2、对前面的代码进行优化,用for,while,if,def实现
a、画五角星
import turtleturtle.setup(600,400)for i in range(5): turtle.forward(100) turtle.right(144)
b、画同心圆
import turtlefor i in range(5): turtle.up() turtle.goto(0,-30*(i+1)) turtle.down() turtle.circle(30*(i+1))
c、画太阳花
import turtle turtle.color('red','blue')turtle.begin_fill()while True: turtle.forward(360) turtle.left(150) if(abs(turtle.pos()))<1: breakturtle.end_fill()done
d、画五个角星
import turtleturtle.setup(700,500,0,0)turtle.color('yellow')turtle.bgcolor('red')turtle.fillcolor('yellow')def my_goto(x,y): turtle.up() turtle.goto(x,y) turtle.down()def my_wujiaoxing(r): turtle.begin_fill() for i in range(5): turtle.forward(r) turtle.right(144) turtle.end_fill()my_goto(-335,160)my_wujiaoxing(100)my_goto(-200,240)my_wujiaoxing(50)my_goto(-150,180)my_wujiaoxing(50)my_goto(-150,100)my_wujiaoxing(50)my_goto(-200,30)my_wujiaoxing(50)