zoukankan      html  css  js  c++  java
  • 9.12

    注意标准库的两种导入与使用方式,建议大家采用<库名>.<函数名>的方式。

    对前面的代码进行优化,用for,while,if,def实现:

    画五角星

    import turtle
    turtle.color('yellow','yellow')
    turtle.begin_fill()
    for i in range(5):
    turtle.forward(200)
    turtle.right(144)
    turtle.end_fill()

    画同心圆

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

    画太阳花

    import turtle
    turtle.color('red','blue')
    turtle.begin_fill()
    while True:
    turtle.forward(200)
    turtle.left(165)
    if(abs(turtle.pos()))<1:
    break
    turtle.end_fill()

    画五个角星

    import turtle
    turtle.color('yellow','yellow')
    turtle.bgcolor('red')
    def lmhgoto(x,y):
    turtle.up()
    turtle.goto(x,y)
    turtle.down()
    lmhgoto(-250,100)
    turtle.begin_fill()
    for i in range(5):
    turtle.forward(125)
    turtle.right(144)
    turtle.end_fill()
    lmhgoto(-90,120)
    turtle.begin_fill()
    for i in range(5):
    turtle.forward(30)
    turtle.left(144)
    turtle.end_fill()
    lmhgoto(-120,165)
    turtle.begin_fill()
    for i in range(5):
    turtle.forward(30)
    turtle.left(144)
    turtle.end_fill()
    lmhgoto(-95,65)
    turtle.begin_fill()
    for i in range(5):
    turtle.forward(30)
    turtle.right(144)
    turtle.end_fill()
    lmhgoto(-120,10)
    turtle.begin_fill()
    for i in range(5):
    turtle.forward(30)
    turtle.left(144)
    turtle.end_fill()

  • 相关阅读:
    python网络编程,requests模块
    python操作excel
    python加密模块hashlib
    python操作redis
    python操作mysql
    python常用模块3(os和sys模块)
    python打开网站
    python常用模块2
    python模块简介
    mac下开发——环境心得(杂项,持续性更新)
  • 原文地址:https://www.cnblogs.com/liminghui3/p/7509609.html
Copyright © 2011-2022 走看看