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

时间:2023-02-13 22:34:16
  1. 画五角星
    import turtle

    turtle.color(
    'yellow')
    turtle.bgcolor(
    'red')
    turtle.fillcolor(
    'yellow')

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

    lh_star(
    150)

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

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

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

  3. 画太阳花
    import  turtle
    turtle.color(
    'black')
    turtle.fillcolor(
    'red')
    turtle.begin_fill()
    while True:
    turtle.forward(
    200)
    turtle.left(
    170)
    if(abs(turtle.pos()))<1:
    break
    turtle.end_fill()

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

  4. 画五个五角星
    import turtle

    turtle.color(
    'yellow')
    turtle.bgcolor(
    'red')
    turtle.fillcolor(
    'yellow')

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

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

    lh_goto(
    -275,175)
    lh_star(
    100)

    lh_goto(
    -175,50)
    lh_star(
    50)

    lh_goto(
    -100,100)
    lh_star(
    50)

    lh_goto(
    -100,175)
    lh_star(
    50)


    lh_goto(
    -170,250)
    lh_star(
    50)

    turtle.hideturtle()

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

  5.  

    画◇花瓣的太阳花
    import  turtle
    turtle.color(
    'white')
    turtle.bgcolor(
    'black')
    turtle.speed(
    10)
    def lh_ling(a):
    for i in range(2):
    turtle.forward(a)
    turtle.right(
    30)
    turtle.forward(a)
    turtle.right(
    150)

    for i in range(36):
    lh_ling(
    50)
    turtle.left(
    170)

    turtle.goto(0,
    -150)
    turtle.hideturtle()

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