条件循环函数定义 练习
Posted 回忆。。
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了条件循环函数定义 练习相关的知识,希望对你有一定的参考价值。
1.注意标准库的两种导入与使用方式,建议大家采用<库名>.<函数名>的方式。
2.对前面的代码进行优化,用for,while,if,def实现:
a.画五角星
import turtle turtle.speed (10) turtle.setup(600,400,0,0) turtle.color("yellow") turtle.fillcolor("yellow") turtle.up() turtle.goto(-250,75) turtle.down() turtle.begin_fill() for i in range(5): turtle.forward(100) turtle.right(144) turtle.end_fill()
b.画同心圆
#同心圆
from turtle import*
speed (10)
for i in range(10):
up()
goto(0,-20*(i+1))
down()
circle(20*(i+1))
c.画太阳花
from turtle import* speed (10) color(\'red\',\'yellow\') begin_fill() while True: forward(200) left(170) if (abs(pos()))<1: break end_fill() done()
d.画五个五角星
import turtle turtle.speed(10) turtle.bgcolor ("red") turtle.color("yellow") turtle.fillcolor("yellow") turtle.begin_fill() def it_goto(x,y): turtle.up() turtle.goto(x,y) turtle.down() def it_star(a): for i in range(5): turtle.forward(a) turtle.right(144) def it_left(b): turtle.left(b) def it_right(b): turtle.right(b) turtle.begin_fill() it_goto(-550,200) it_star(200) turtle.end_fill() turtle.begin_fill() it_goto(-260,300) it_right(20) it_star(50) it_left(20) turtle.end_fill() turtle.begin_fill() it_goto(-230,200) it_left(20) it_star(50) it_right(20) turtle.end_fill() turtle.begin_fill() it_goto(-230,130) it_right(20) it_star(50) it_left(20) turtle.end_fill() turtle.begin_fill() it_goto(-270,50) it_right(20) it_star(50) it_left(20) turtle.end_fill() turtle.hideturtle()
e.画◇花瓣的太阳花。
import turtle turtle.speed(10) turtle.color(\'red\') turtle.fillcolor(\'yellow\') turtle.begin_fill() for i in range(36): for j in range(2): turtle.forward(100) turtle.right(45) turtle.forward(100) turtle.right(135) turtle.right(10) turtle.right(90) turtle.forward(400) turtle.end_fill()
以上是关于条件循环函数定义 练习的主要内容,如果未能解决你的问题,请参考以下文章