• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
陈华斐
博客园    首页    新随笔    联系   管理    订阅  订阅
条件、循环、函数定义 练习
  1. 注意标准库的两种导入与使用方式,建议大家采用<库名>.<函数名>的方式。
  2. 对前面的代码进行优化,用for,while,if,def实现:

a.画五角星

 

import turtle
turtle.setup(600,400,0,0)
turtle.color('yellow')
turtle.bgcolor('red')
turtle.fillcolor('yellow')
def mygoto(x,y):
turtle.up()
turtle.goto(x,y)
turtle.down()
mygoto(-250,75)
turtle.begin_fill()

for i in range(5):
turtle.forward(50)
turtle.right(144)
turtle.end_fill()

 

b.画同心圆

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

 

c.画太阳花

import turtle
turtle.color('blue')
turtle.fillcolor('white')
turtle.bgcolor('pink')
from turtle import*
color('red','blue')
turtle.begin_fill()
while True:
turtle.forward(200)
turtle.left(160)
if(abs(turtle.pos()))<1:
break
turtle.end_fill()

 

d.画五个角星

 

import turtle
turtle.color('yellow')
turtle.fillcolor('yellow')
turtle.bgcolor('red')
j=-250
k=-250
turtle.begin_fill()
for i in range(5):
turtle.up()
turtle.goto(j+(i*150),k+(i*150))
turtle.down()
for i in range(5):
turtle.forward(100)
turtle.right(144)
turtle.end_fill()

 

 

posted on 2017-09-12 09:58  026陈华斐  阅读(188)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3