条件循环函数定义 练习
Posted 李笑晴
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了条件循环函数定义 练习相关的知识,希望对你有一定的参考价值。
1.画五角星
import turtle turtle.speed(10) turtle.bgcolor("black") turtle.color("yellow") turtle.fillcolor("red") turtle.begin_fill() for i in range(5): turtle.forward(100) turtle.right(144) turtle.end_fill() turtle.hideturtle()
截图:
2.画同心圆
import turtle turtle.color("white") turtle.bgcolor("red") for i in range(5): turtle.up() turtle.goto(0,-20*(i+1)) turtle.down() turtle.circle(20*(i+1)) turtle.hideturtle()
截图:
3.画太阳花
import turtle turtle.speed(10) turtle.bgcolor("black") turtle.color("cyan") turtle.fillcolor("yellow") turtle.begin_fill() while True: turtle.forward(200) turtle.left(170) if(abs(turtle.pos()))<1: break turtle.end_fill() turtle.hideturtle()
截图:
4.画五个五角星
import turtle turtle.color(\'yellow\') turtle.bgcolor(\'red\') turtle.fillcolor(\'yellow\') def my_goto(x,y): turtle.up() turtle.goto(x,y) turtle.down() def my_draw5(r): turtle.begin_fill() for i in range(5): turtle.forward(r) turtle.right(144) turtle.end_fill() my_goto(-675,240) my_draw5(100) my_goto(-550,300) my_draw5(35) my_goto(-525,245) my_draw5(35) my_goto(-530,185) my_draw5(35) my_goto(-560,145) my_draw5(35) turtle.hideturtle()
截图:
5.画◇花瓣的太阳花。
import turtle def draw_diamond(brad): brad.forward(100) brad.left(45) brad.forward(100) brad.left(135) def draw_art(): window=turtle.Screen() window.bgcolor("pink") brad=turtle.Turtle() brad.shape("turtle") brad.color("cyan") brad.speed(10) for i in range(1,37): draw_diamond(brad) draw_diamond(brad) brad.left(10) brad.right(90) brad.forward(300) window.exitionclick() draw_art()
截图:
以上是关于条件循环函数定义 练习的主要内容,如果未能解决你的问题,请参考以下文章