条件、循环、函数定义 练习
2017-09-12 13:35 019王泽 阅读(132) 评论(0) 收藏 举报- 注意标准库的两种导入与使用方式,建议大家采用<库名>.<函数名>的方式。
- 对前面的代码进行优化,用for,while,if,def实现:
画五角星
import turtle
for i in range(5):
turtle.forward(150)
turtle.left(144)
画同心圆
import turtle
for i in range(5):
turtle.up()
turtle.goto(0,-20*(i+1))
turtle.down()
turtle.circle(20*i)
画太阳花
import turtle
turtle.color('red','blue')
while True:
turtle.forward(150)
turtle.left(170)
if(abs(turtle.pos()))<1:
break
画五个角星
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(25)
mygoto(-110,250)
ye(25)
mygoto(-110,190)
ye(25)
mygoto(-160,140)
ye(25)
浙公网安备 33010602011771号