条件循环函数定义 练习
Posted Mavelon
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了条件循环函数定义 练习相关的知识,希望对你有一定的参考价值。
前面的代码进行优化,用for,while,if,def实现:
1.画五角星
import turtle
for i in range(5):
turtle.forward(100);
turtle.right(144);
2.画同心圆
import turtle
def circle(x):
turtle.up()
turtle.goto(0,-x)
turtle.down()
turtle.circle(x+10)
for i in range(5):
circle((i+1)*20)
3.画太阳花
import turtle
turtle.begin_fill()
turtle.fillcolor(\'pink\')
turtle.speed(100)
while True:
turtle.forward(200)
turtle.left(170)
if(abs(turtle.pos()))<1:
turtle.end_fill()
break
4.画五个角星
import turtle
turtle.setup(600,400,0,0)
turtle.color("yellow")
turtle.bgcolor("red")
turtle.fillcolor(\'yellow\')
turtle.speed(100)
turtle.begin_fill()
def reposi(x,y):
turtle.up()
turtle.goto(x,y)
turtle.down()
reposi(-250,75)
for i in range(5):
turtle.forward(100);
turtle.right(144);
turtle.end_fill()
reposi(-130,120)
turtle.begin_fill()
for i in range(5):
turtle.forward(30);
turtle.right(144);
turtle.end_fill()
reposi(-110,80)
turtle.begin_fill()
for i in range(5):
turtle.forward(30);
turtle.right(144);
turtle.end_fill()
reposi(-110,40)
turtle.begin_fill()
for i in range(5):
turtle.forward(30);
turtle.right(144);
turtle.end_fill()
reposi(-130,0)
turtle.begin_fill()
for i in range(5):
turtle.forward(30);
turtle.right(144);
turtle.end_fill()
以上是关于条件循环函数定义 练习的主要内容,如果未能解决你的问题,请参考以下文章