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

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

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

    a.画五角星

    import turtle
    
    turtle.color("yellow")
    turtle.bgcolor("red")
    turtle.fillcolor("yellow")
    
    def star_goto(x,y):
        turtle.up()
        turtle.goto(x,y)
        turtle.down()
    
    def star_draw(r):
        turtle.begin_fill()
        for i in range(5):
            turtle.forward(r)
            turtle.left(144)
        turtle.end_fill()
    
    star_goto(-300,105)
    star_draw(100)

    b.画同心圆

    import turtle
    turtle.color('red')
    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('green')
    turtle.fillcolor('yellow')
    turtle.begin_fill()
    while True:
        turtle.forward(200)
        turtle.left(170)
        if(abs(turtle.pos()))<1:
           break
    
    turtle.end_fill()
    done()

    d.画五个五角星

    import turtle
    
    turtle.color("yellow")
    turtle.bgcolor("red")
    turtle.fillcolor("yellow")
    
    def star_goto(x,y):
        turtle.up()
        turtle.goto(x,y)
        turtle.down()
    
    def star_draw(r):
        turtle.begin_fill()
        for i in range(5):
            turtle.forward(r)
            turtle.left(144)
        turtle.end_fill()
    
    star_goto(-300,105)
    star_draw(100)
    
    star_goto(-200,200)
    star_draw(50)
    
    star_goto(-150,150)
    star_draw(50)
    
    star_goto(-150,100)
    star_draw(50)
    
    star_goto(-200,50)
    star_draw(50)

    e.画◇花瓣的太阳花。

    import turtle
    def my_lx(brad):
        brad.forward(100)
        brad.right(45)
        brad.forward(100)
        brad.right(135)
    
    def my_art():
        window=turtle.Screen()
        window.bgcolor("green")
        brad=turtle.Turtle()
        brad.shape("turtle")
        brad.color("orange")
        brad.speed('fastest')
        for i in range(1,37):
            my_lx(brad)
            my_lx(brad)
            brad.left(10)
        brad.right(90)
        brad.forward(300)
    my_art()

  • 相关阅读:
    netCore3.1项目搭建过程记录-省的每次都傻乎乎的不知道应该先干啥
    探究 position-sticky 失效问题
    协议的设计一般采用结构体进行数据打包,在协议设计的结构体中能不能使用指针 ?
    ROS pluginlib
    ROS NodeHandle命令空间问题
    ROS 常见命令
    ROS ros::spin() 和 ros::spineOnce区别
    PPM图像文件格式
    Qtcreator for visual studio版本调试问题
    Install Typora For Linux
  • 原文地址:https://www.cnblogs.com/00js/p/7515589.html
Copyright © 2011-2022 走看看