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 <= 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 <= width:
    print("#"*num_width,end="\n")
    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="\n")
    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 <= width:
        print(str(num_width)+"*"+str(width)+"="+str(num_width*width),end="\t")
        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 <= width:
        print(str(num_width)+"*"+str(width)+"="+str(num_width*width),end="\t")
        num_width += 1
    print()
    width -= 1

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

python while嵌套循环的更多相关文章

  1. Python For嵌套循环 图形打印X型 nested loop -练习题

    For嵌套循环图形打印作业很多是C++语言做的,我觉得Python应该也能做,就来试一试. 原网址C++练习题:http://www.imooc.com/qadetail/216848?t=33880 ...

  2. Python For嵌套循环 图形打印X型 nested loop - 练习题答案

    上一篇:Python For嵌套循环 图形打印X型 nested loop - 练习题 上一篇留的Python For嵌套循环 图形打印X型练习题的答案. 由于网上很多嵌套循环都是C++语言写的,用P ...

  3. [Python] For 嵌套循环打印图形 nested loop-练习题答案

    前一篇:[Python] For 嵌套循环打印图形 nested loop-练习题 [python的for循环嵌套打印如下图形] 图形一: 输出结果: ******* ******* ******* ...

  4. [Python] For 嵌套循环打印图形 nested loop - 练习题

    [python的for循环嵌套打印如下图形] 图形一: ******* ******* ******* ******* 图形二: * *** ***** ******* 图形三: * *** **** ...

  5. python 跳出嵌套循环方法

    class LoopError(Exception):pass rs = '' try: for i in range(1, 3): print i rs = 'one ' if i == 1: fo ...

  6. [Python]循环嵌套nested loop-练习题

    [python的for循环嵌套打印如下图形] 图形一: ******* ******* ******* ******* 图形二: * *** ***** ******* 图形三: * *** **** ...

  7. python使用笔记

    修改文件模板,支持中文. File -> Settings -> Editor -> File and Code templates -> python Scropt 在里面加 ...

  8. python基础-循环语句for\嵌套循环

    for循环格式: for index in range(0,3):#等同于range(3),取0\1\2 print(index) index = 0 starnames = ['xr1','xr2' ...

  9. 一文了解Python中的循环(for while break continue 嵌套循环...)

    循环 目标 程序的三大流程 while 循环基本使用 break 和 continue while 循环嵌套 01. 程序的三大流程 在程序开发中,一共有三种流程方式: 顺序 —— 从上向下,顺序执行 ...

随机推荐

  1. App主导现在 HTML5领衔未来

    HTML5能够让开发人员构建丰富的基于Web应用程序,使其能在任何设备中使用标准的Web浏览器.很多人认为HTML5将会让App过时.到底App还是HTML5会是谁赢得最后的胜利,在业界也有不少讨论, ...

  2. LinkServer--服务器选项

    1. RPC和RPC out 当RPC和RPC out被设置为true时,允许调用远程服务器的存储过程 2.为RPC启用针对分布式事务的升级 使用该选项可通过 Microsoft 分布式事务处理协调器 ...

  3. [翻译]NUnit---TearDown and SetUpFixture and Test Attributes(二十)

    TearDownAttribute (NUnit 2.0 / 2.5) 本特性在TestFixture内部使用,每个测试方法执行后调用的方法集.也可以在SetUpFixture中使用,在同一命名空间或 ...

  4. NetMQ 消息队列

    忘记是看到哪个博客写的了,如有侵权,请见谅!! 1.辅助Helper类 (添加System.Messaging引用) using System; using System.Collections.Ge ...

  5. 基于jTopo的拓扑图设计工具库ujtopo

    绘制拓扑图有很多开源的工具,知乎上也有人回答了这个问题: https://www.zhihu.com/question/41026400/answer/118726253 ujtopo是基于jTopo ...

  6. 记录.NET Core部署到Linux之.NET Core环境搭建(1)

    1.在安装.NET之前,您需要注册Microsoft密钥.注册产品存储库和安装所需的依赖项. 启动我们的虚拟机,输入以下命令: sudo rpm -Uvh https://packages.micro ...

  7. svn 连接超时,连接失败解决办法

    1.确认服务是否开启 2.Windows防火墙是否开启,如开启则关闭防火墙 3.安全软件是否将3306与443端口关闭. 关闭后无法连接

  8. Linux core 文件 gdb

    http://blog.csdn.net/mr_chenping/article/details/13767609 在程序不寻常退出时,内核会在当前工作目录下生成一个core文件(是一个内存映像,同时 ...

  9. PyMysql复习

    参考:http://www.cnblogs.com/liwenzhou/p/8032238.html 使用pycharm操作数据库. 填一个数据库名,User:填root 填写要连接的数据库. 建表. ...

  10. 算法(Algorithm)

    算法就是"把解决问题的步骤无一遗漏地用文字或图表示出来". 在解决问题的步骤中,有了与直觉相关的因素,就不是算法了.既然不是算法,也就不能用程序表示了.