条件循环函数定义 练习
Posted 18-刘卓辉
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了条件循环函数定义 练习相关的知识,希望对你有一定的参考价值。
用循环画五角星
from turtle import * for i in range(5): forward(200) right(144)
用循环画同心圆
from turtle import * for i in range(5): up() goto(0,-20*i) down() circle(20*i)
用while循环画太阳花
from turtle import * color(\'red\',\'yellow\') speed(\'fastest\') begin_fill() while True: forward(200) left(170) if abs(pos())<1: break end_fill() done()
用函数定义画五个五角星
from turtle import * setup(600,400,0,0) bgcolor(\'red\') color(\'yellow\') fillcolor(\'yellow\') speed(\'fastest\') def mark_star(x,y): up() goto(x,y) down() def draw_star(x,y): begin_fill() for i in range(5): forward(x) right(y) end_fill() mark_star(-260,120) draw_star(120,144) mark_star(-120,160) draw_star(40,144) mark_star(-80,120) draw_star(40,144) mark_star(-80,60) draw_star(40,144) mark_star(-120,20) draw_star(40,144) color(\'red\')
用函数定义画钻石花瓣的太阳花
import turtle def draw_diamond(brad): brad.forward(100) brad.right(45) brad.forward(100) brad.right(135) def draw_art(): window=turtle.Screen() window.bgcolor("red") brad=turtle.Turtle() brad.shape("turtle") brad.color("orange") brad.speed("fastest") for i in range(0,36): draw_diamond(brad) draw_diamond(brad) brad.left(10) brad.right(90) brad.forward(155) brad.color(\'green\') brad.forward(145) window.exitonclick() draw_art()
以上是关于条件循环函数定义 练习的主要内容,如果未能解决你的问题,请参考以下文章