条件循环函数定义 练习
Posted 郑淑莹
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了条件循环函数定义 练习相关的知识,希望对你有一定的参考价值。
a.画五角星
import turtle for i in range(5): turtle.forward(100) turtle.right(144)
b.画同心圆
from turtle import* for i in range(5): up() goto(0,-20*(1+i)) down() circle(20*(1+i))
c.画太阳花
from turtle import* color(\'pink\',\'yellow\') begin_fill() while True: forward(200) right(150) if(abs(pos()))<1: break end_fill() hideturtle()
d.画五个角星
import turtle turtle.setup(600,400,0,0) turtle.color(\'yellow\') turtle.bgcolor(\'red\') turtle.fillcolor(\'yellow\') def lsw_goto(x,y): turtle.up() turtle.goto(x,y) turtle.down() def lsw_draw5(r): turtle.begin_fill() for i in range(5): turtle.forward(r) turtle.right(144) turtle.end_fill() lsw_goto(-250,80) lsw_draw5(100) lsw_goto(-150,150) lsw_draw5(50) lsw_goto(-100,100) lsw_draw5(50) lsw_goto(-90,45) lsw_draw5(50) lsw_goto(-150,5) lsw_draw5(50) turtle.hideturtle()
e.画◇花瓣的太阳花
import turtle turtle.color(\'yellow\',\'blue\') turtle.bgcolor(\'pink\') turtle.begin_fill() for i in range(1,37): turtle.forward(200) turtle.right(45) turtle.forward(200) turtle.right(135) turtle.forward(200) turtle.right(45) turtle.forward(200) turtle.right(135) turtle.left(10) turtle.speed("fastest") turtle.right(90) turtle.forward(500) turtle.end_fill() turtle.hideturtle()
以上是关于条件循环函数定义 练习的主要内容,如果未能解决你的问题,请参考以下文章