- 注意标准库的两种导入与使用方式,建议大家采用<库名>.<函数名>的方式。
- 对前面的代码进行优化,用for,while,if,def实现:
- 画五角星
import turtle
turtle.speed(6)
for i in range(5):
turtle.forward(100)
turtle.right(144)
turtle.hideturtle() - 画同心圆
import turtle
for i in range(9):
turtle.up()
turtle.goto(0,-20*(i+1))
turtle.down()
turtle.circle(20*(i+1))
turtle.hideturtle() - 画太阳花
import turtle
turtle.speed(10)
turtle.color('blue','yellow')
turtle.begin_fill()
while True:
turtle.forward(250)
turtle.left(170)
if(abs(turtle.pos()))<1:
break
turtle.end_fill()
done() - 画五个五角星
import turtle
turtle.speed(10)
turtle.color('yellow')
turtle.bgcolor('red')
def mygoto(x,y):
turtle.up()
turtle.goto(x,y)
turtle.down()
def drawfive(r):
turtle.begin_fill()
for i in range(5):
turtle.forward(r)
turtle.right(144)
turtle.end_fill()
#大星
mygoto(-300,150)
drawfive(100)
#小星
mygoto(-200,230)
drawfive(50)
mygoto(-150,170)
drawfive(50)
mygoto(-150,100)
drawfive(50)
mygoto(-200,50)
drawfive(50)
turtle.hideturtle() - 画◇花瓣的太阳花
import turtle
turtle.speed(10)
turtle.color("blue")
turtle.fillcolor('yellow')
def drawlx():
for i in range(1,3):
turtle.forward(100)
turtle.right(45)
turtle.forward(100)
turtle.right(135)
for i in range(1,40):
turtle.begin_fill()
drawlx()
turtle.right(20)
turtle.end_fill()
turtle.right(90)
turtle.hideturtle()
- 画五角星
相关文章
- Python应用练习题(第二期)——条件语句&循环嵌套的应用
- 五、Angular定义字段、绑定字段、获取数据、对象获取数据、*ngFor循环获取数据,自定义方法、*ngIf条件判断、双向数据绑定
- 我的一个PLSQL函数 先查询再插入数据库的函数 动态SQL拼接查询条件、通用游标、记录定义(封装部分查询字段并赋值给游标)、insert select 序列、常量【我】
- go语言练习:条件语句和循环语句
- for循环的运算 改变循环的控制流 死循环 遍历数组 定义方法 有名函数匿名函数 定义函数的方法取值 与 自己创建函数取值 局部与全局变量 次幂/随机数/取绝对值/向上取整/平方根
- 【Python基础学习二】定义变量、判断、循环、函数基本语法
- (Excel)常用函数公式及操作技巧之六:条件自定义格式(一)
- Python循环语句及函数的定义
- Python 循环与定义函数
- 大数据学习day13------第三阶段----scala01-----函数式编程。scala以及IDEA的安装,变量的定义,条件表达式,for循环(守卫模式,推导式,可变参数以及三种遍历方式),方法定义,数组以及集合(可变和非可变),数组中常用的方法