• python while嵌套循环


    while循环
    1、输出打印以#组成的长方形,自己定义长和宽。
    # -*-encoding:utf-8-*-
    '''
    This is script for start docker containor!
    Auth: cuishuai
    '''
    height = int(input("Height:"))
    width  = int(input("Width:"))
    num_height = 1

    while num_height <= height:
        num_width = 1
        while num_width <=
            num_width += 1
            print("#",end="")
        num_height += 1
        print()

    2、输出如下图形
       *
       * *
       * * *
       * * * *
    # -*-encoding:utf-8-*-
    '''
    This is script for start docker containor!
    Auth: cuishuai
    '''
    width  = int(input("Width:"))
    num_width = 1
    while num_width <=
        print("#"*num_width,end=" ")
        num_width += 1
    3、输出2的倒叙图形:
      * * * *
      * * *
      * *
      *
    # -*-encoding:utf-8-*-
    '''
    This is script for start docker containor!
    Auth: cuishuai
    '''
    width  = int(input("Width:"))
    while width > 0:
        print("#"*width,end=" ")
        width -= 1

    第二种实现方式,使用嵌套循环:
    # -*-encoding:utf-8-*-
    '''
    This is script for start docker containor!
    Auth: cuishuai
    '''
    width  = int(input("Width:"))
    while width > 0:
        num_width = width
        while num_width > 0:
            print("*",end="")
            num_width -= 1
        print()
        width -= 1

    5、输出99乘法表
    # -*-encoding:utf-8-*-
    '''
    This is script for start docker containor!
    Auth: cuishuai
    '''
    width  = 1
    while width <= 9:
        num_width = 1
        while num_width <=
            print(str(num_width)+"*"+str(width)+"="+str(num_width*width),end=" ")
            num_width += 1
        print()
        width += 1
    倒叙99表
    # -*-encoding:utf-8-*-
    '''
    This is script for start docker containor!
    Auth: cuishuai
    '''
    width  = 9
    while width > 0:
        num_width = 1
        while num_width <=
            print(str(num_width)+"*"+str(width)+"="+str(num_width*width),end=" ")
            num_width += 1
        print()
        width -= 1

    注释:end=表示每一行的结尾, 表示换行符, 表示制表符

    --------崔帅的拾荒
  • 相关阅读:
    javascript小记
    好看的echart的词云效果(wordCloud)
    工作中经常用到的git的简单操作记录
    积累就是提升之浅谈分时函数
    有意思的面试小试题
    分享张鑫旭大神的,纯css打字小技巧,我顺便收藏一下
    模仿也是提高,纯css小技巧实现头部进度条
    推荐好用的css调试工具,两个
    There appears to be trouble with your network connection. Retrying
    Enter passphrase for key ‘/root/.ssh/id_rsa’ : git push 重复输入密码的问题
  • 原文地址:https://www.cnblogs.com/cuishuai/p/7242558.html
Copyright © 2020-2023  润新知