条件、循环、函数定义 练习
1.画五角星
import turtle turtle.shape('turtle') turtle.color('yellow') turtle.fillcolor('yellow') turtle.begin_fill() for i in range(5): turtle.forward(100) turtle.right(144) turtle.end_fill() turtle.hideturtle() turtle.done()

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

3.画太阳花
import turtle turtle.fillcolor("yellow") turtle.begin_fill() while True: turtle.forward(200) turtle.left(170) if(abs(turtle.pos()))<1: break turtle.end_fill() turtle.hideturtle()

4.画五个五角星
import turtle turtle.setup(600,400,0,0) turtle.color('yellow') turtle.fillcolor('yellow') turtle.bgcolor('red') def my_goto(x,y): turtle.up() turtle.goto(x,y) turtle.down() def my_draw5(r): turtle.begin_fill() for i in range(5): turtle.forward(r) turtle.right(144) turtle.end_fill() my_goto(-300,150) my_draw5(100) my_goto(-200,250) my_draw5(50) my_goto(-100,200) my_draw5(50) my_goto(-100,80) my_draw5(50) my_goto(-100,0) my_draw5(50) turtle.hideturtle()
turtle.done()

5.画◇花瓣的太阳花。
import turtle turtle.speed(10) turtle.fillcolor("yellow") turtle.pencolor("red") turtle.begin_fill() def draw_leng(): for i in range(1,3): turtle.forward(100) turtle.right(45) turtle.forward(100) turtle.right(135) for i in range(1,37): draw_leng() turtle.right(10) turtle.end_fill() turtle.right(90) turtle.forward(300) turtle.hideturtle()

浙公网安备 33010602011771号