首页 > 其他 > 详细

条件、循环、函数定义 练习

时间:2017-09-12 14:47:23      阅读:239      评论:0      收藏:0      [点我收藏+]
  1. 注意标准库的两种导入与使用方式,建议大家采用<库名>.<函数名>的方式。
  2. 对前面的代码进行优化,用for,while,if,def实现:

画五角星

import turtle
for i in range(5):
   turtle.forward(150)
   turtle.left(144)

画同心圆

import turtle
for i in range(5):
   turtle.up()
   turtle.goto(0,-20*(i+1))
   turtle.down()
   turtle.circle(20*i)

画太阳花

import turtle
turtle.color(‘red‘,‘blue‘)
while True:
   turtle.forward(150)
   turtle.left(170)
   if(abs(turtle.pos()))<1:
       break

画五个角星

import turtle
turtle.color(‘yellow‘)
turtle.bgcolor(‘red‘)   
turtle.fillcolor(‘yellow‘)

def mygoto(x,y):
 turtle.up()
 turtle.goto(x,y)
 turtle.down()

def ye(r):
 turtle.begin_fill()
 for i in range(5):
      turtle.forward(r)
      turtle.right(144)
 turtle.end_fill()

mygoto(-320,250)
ye(100)
mygoto(-160,300)
ye(25)
mygoto(-110,250)
ye(25)
mygoto(-110,190)
ye(25)
mygoto(-160,140)
ye(25)

条件、循环、函数定义 练习

原文:http://www.cnblogs.com/wangze019/p/7509691.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!