条件、循环、函数定义 练习
1.画五角星
import turtle for i in range(5): turtle.forward(100); turtle.right(144);
运行结果:
2.画同心圆
from turtle import* for i in range(5): up() goto(0,-20*(i+1)) down() circle(20*(i+1))
运行结果:
3.画太阳花
from turtle import* while True: forward(200) left(170) if (abs(pos()))<1: break done()
运行结果为:
4.画五个五角星
import turtle turtle.color('yellow') turtle.bgcolor('red') def DrawStar(x,y,a,b): turtle.begin_fill() turtle.up() turtle.goto(x,y) for i in range(5): turtle.forward(a) turtle.right(b) turtle.end_fill() DrawStar(-250,75,150,144) DrawStar(-100,150,50,144) DrawStar(-80,80,50,144) DrawStar(-75,23,50,144) DrawStar(-100,-35,50,144)
运行结果为: