zoukankan      html  css  js  c++  java
  • 条件、循环、函数定义 练习

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

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

    a.画五角星

    b.画同心圆

    c.画太阳花

    d.画五个角星

    a.

    >>> turtle.reset()
    >>> turtle.color('yellow')
    >>> turtle.fillcolor('yellow')
    >>> turtle.begin_fill()
    >>> for i in range(5):
    turtle.forward(200)
    turtle.left(144)


    >>> turtle.end_fill()

    b.

    >>> turtle.reset()
    >>> for i in range(5):
    turtle.circle(20*(i+1))
    turtle.up()
    turtle.right(90)
    turtle.forward(20)
    turtle.left(90)
    turtle.down()

    c.

    import turtle
    turtle.color('red')
    turtle.fillcolor('yellow')
    turtle.begin_fill()
    while True:
        turtle.forward(200)
        turtle.left(80)
        if abs(turtle.pos())<1:
            break
    turtle.end_fill()

    d.

    import turtle
    turtle.bgcolor('red')
    turtle.color('yellow')
    turtle.fillcolor('yellow')
    turtle.begin_fill()
    turtle.up()
    turtle.goto(-200,50)
    turtle.down()
    for i in range(5):
        turtle.forward(200)
        turtle.left(144)
    turtle.end_fill()
    turtle.up()
    turtle.left(35)
    turtle.forward(300)
    turtle.down()
    turtle.fillcolor('yellow')
    turtle.begin_fill()
    for i in range(5):
        turtle.forward(50)
        turtle.left(144)
    turtle.end_fill()
    turtle.up()
    turtle.right(90)
    turtle.forward(100)
    turtle.left(90)
    turtle.down()
    turtle.fillcolor('yellow')
    turtle.begin_fill()
    for i in range(5):
        turtle.forward(50)
        turtle.left(144)
    turtle.end_fill()
    turtle.up()
    turtle.right(120)
    turtle.forward(100)
    turtle.left(120)
    turtle.down()
    turtle.fillcolor('yellow')
    turtle.begin_fill()
    for i in range(5):
        turtle.forward(50)
        turtle.left(144)
    turtle.end_fill()
    turtle.up()
    turtle.right(150)
    turtle.forward(100)
    turtle.left(150)
    turtle.down()
    turtle.fillcolor('yellow')
    turtle.begin_fill()
    for i in range(5):
        turtle.forward(50)
        turtle.left(144)
    turtle.end_fill()

  • 相关阅读:
    字符串比较
    LOOP AT SCREEN
    Trunc的日期用法
    【ABAP】SELECT-ENDSELECT尽量不要用
    【转】Abap For all entries in 使用
    01如何创建sequence:
    abap --MOVE-CORRESPONDING
    Abap 常用变量
    StringBuffer的用法
    Spring事务的传播方式
  • 原文地址:https://www.cnblogs.com/GAODASHANG/p/7512436.html
Copyright © 2011-2022 走看看