条件、循环、函数定义 练习

  1. 注意标准库的两种导入与使用方式,建议大家采用<库名>.<函数名>的方式。
  2. 对前面的代码进行优化,用for,while,if,def实现:
    1. 画五角星
      import turtle
      for i in range(5):
        turtle.forward(100)
        turtle.left(144)
        turtle.speed(8)

       

    2. 画同心圆
      import turtle
      for i in range(3):
         turtle.up()
         turtle.goto(0,-30*(i+1))
         turtle.down()
         turtle.circle(30*i)

       

    3. 画太阳花
      import turtle
      turtle.color('red','orange')
      turtle.speed(10)
      turtle.begin_fill()
      while True:
         turtle.forward(150)
         turtle.left(170)
         if(abs(turtle.pos()))<1:
             turtle.end_fill()
             break

       

    4. 画五个角星
      import turtle
      turtle.color('yellow')
      turtle.bgcolor('red')    
      turtle.fillcolor('yellow')
      
      def mygoto(x,y):
       turtle.up()
       turtle.goto(x,y)
       turtle.down()
      
      def ye(r):
       turtle.begin_fill()
       for i in range(5):
            turtle.forward(r)
            turtle.right(144)
       turtle.end_fill()
      
      mygoto(-320,250)
      ye(100)
      mygoto(-160,300)
      ye(30)
      mygoto(-110,250)
      ye(30)
      mygoto(-110,190)
      ye(30)
      mygoto(-160,140)
      ye(30)



posted @ 2017-09-13 16:01  092曹馨文  阅读(109)  评论(0编辑  收藏  举报