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

    问题:

    1. 注意标准库的两种导入与使用方式,建议大家采用<库名>.<函数名>的方式。
    2. 对前面的代码进行优化,用for,while,if,def实现:
      1. 画五角星
      2. 画同心圆
      3. 画太阳花
      4. 画五个角星

    1.画五角星

    代码如下:

    import turtle
    def star(i):
        turtle.forward(50)
        turtle.right(144)
    for i in range(5):
        star(i)

    运行结果:

     2.画同心圆

    代码如下:

    import turtle
    def concentric(i):
        turtle.up()
        turtle.goto(0,-20*(i+1))
        turtle.down()
        turtle.circle(20*(i+1))

    for i in range(5):
        concentric(i)

    运行结果:

     3.画太阳花

    代码如下:

    import turtle
    turtle.color('red','yellow')
    turtle.begin_fill()
    def flower(x,y):
        turtle.forward(x)
        turtle.left(y)
    while True:
        flower(200,165)
        if(abs(turtle.pos()))<1:
            break
    turtle.end_fill()
    turtle.done()

    运行结果:

    4,.画五个角星

    代码如下:

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

    def DrawStar(x,y,a,b):
        turtle.begin_fill()
        turtle.up()
        turtle.goto(x,y)
        for i in range(5):

            turtle.forward(a)
            turtle.right(b)
        turtle.end_fill()

    DrawStar(-250,75,100,144)
    DrawStar(-100,150,50,144)
    DrawStar(-80,80,50,144)
    DrawStar(-75,23,50,144)
    DrawStar(-100,-35,50,144)

    运行结果:

     

  • 相关阅读:
    Centos7.2 下搭建LNMP环境(终极版)Yum安装
    ThinkPHP3.2 插入数据库数据,缓存问题
    无限极分类的JS实现
    PHP 商城无限极分类
    高速下载Centos的地址
    高性能的城市定位API接口
    阿帕奇配置本地虚拟站点,XAMPP环境下
    Nginx 下配置Laravel 错误404
    laravel Redis缓存
    pytest.1.快速开始
  • 原文地址:https://www.cnblogs.com/decadeyu/p/7509808.html
Copyright © 2011-2022 走看看