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

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

c.画太阳花
import turtle while True: turtle.forward(200) turtle.left(170) if(abs(turtle.pos()))<1: break turtle.hideturtle()

d.画五个五角星
import turtle turtle.color('yellow') turtle.fillcolor('yellow') turtle.bgcolor('red') def yf_goto(x,y): turtle.up() turtle.goto(x,y) turtle.down() yf_goto(-600,250) turtle.begin_fill() for i in range(5): turtle.forward(100) turtle.right(144) turtle.end_fill() yf_goto(-450,290) turtle.begin_fill() for i in range(5): turtle.forward(50) turtle.right(144) turtle.end_fill() yf_goto(-420,225) turtle.begin_fill() for i in range(5): turtle.forward(50) turtle.right(144) turtle.end_fill() yf_goto(-445,165) turtle.begin_fill() for i in range(5): turtle.forward(50) turtle.right(144) turtle.end_fill() yf_goto(-485,110) turtle.begin_fill() for i in range(5): turtle.forward(50) turtle.right(144) turtle.end_fill() turtle.hideturtle()

e.画菱形花瓣的太阳花
import turtle def draw_flower(ff): ff.forward(100) ff.right(45) ff.forward(100) ff.right(135) def draw_huahua(): window=turtle.Screen() window.bgcolor('pink') ff=turtle.Turtle() ff.shape("turtle") ff.color("red") ff.speed('fastest') for i in range(1,37): draw_flower(ff) draw_flower(ff) ff.left(10) ff.right(90) ff.foeward(300) window.exitionclick() draw_huahua()

浙公网安备 33010602011771号