循环 函数
画五角星
输入
import turtle turtle.pos() turtle.color('red') for i in range(5): turtle.forward(100) turtle.right(144) turtle.hideturtle()
输出

画同心圆
输入
import turtle turtle.pos() turtle.color('red') for i in range(5): turtle.up() turtle.goto(0,-20*(i+1)) turtle.down() turtle.circle(20*(i+1))
输出

画太阳花
输入
import turtle turtle.color('orange') turtle.fillcolor('pink') turtle.begin_fill() while True: turtle.forward(100) turtle.left(150) if (abs(turtle.pos()))<1: break turtle.end_fill() turtle.hideturtle()
输出

画五个角星
import turtle turtle.pos() turtle.color('yellow') turtle.bgcolor('red') turtle.fillcolor('yellow') turtle.speed(100) def my_goto(x,y): turtle.up() turtle.goto(x,y) turtle.down() def my_star(r): for i in range(5): turtle.forward(r) turtle.right(144) turtle.begin_fill() my_goto(-390,180) my_star(140) turtle.end_fill() turtle.begin_fill() my_goto(-150,240) my_star(40) turtle.end_fill() turtle.begin_fill() my_goto(-90,180) my_star(40) turtle.end_fill() turtle.begin_fill() my_goto(-90,90) my_star(40) turtle.end_fill() turtle.begin_fill() my_goto(-150,30) my_star(40) turtle.end_fill() turtle.hideturtle()
输出

浙公网安备 33010602011771号