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. LeetCode145:Binary Tree Postorder Traversal

    题目: Given a binary tree, return the postorder traversal of its nodes' values. For example: Given bin ...

  2. CentOS7查看CPU个数

    查看逻辑cpu个数:cat /proc/cpuinfo | grep "processor" | wc -l 查看物理cpu个数:cat /proc/cpuinfo | grep ...

  3. ASP.NET Core真实管道详解[1]

    ASP.NET Core管道虽然在结构组成上显得非常简单,但是在具体实现上却涉及到太多的对象,所以我们在 <ASP.NET Core管道深度剖析[共4篇]> 中围绕着一个经过极度简化的模拟 ...

  4. Oracle数据库多行记录转换一行并排序函数

    Oracle数据库多行记录转换一行并排序方法 在ORACLE数据库查询中,我们通常会要求用到将多行记录转换成一行并排序,这时候我们自然会想到Oracle的一个“wx_concat”函数,可以将多行记录 ...

  5. MaxScript调用DotNet时命名空间的问题

    Fn GetSpecialFolder argEnumName = (DotNetClass "System.Environment").GetFolderPath (Execut ...

  6. 关于win10 链接安卓设备报错winusb.sys未经签名的解决办法

    很简单,各位,我找了一个签过名的winusb.sys替换原来的文件即可. 操作系统win10 64位专业版(更新到最新版本了) 网盘地址 安装好以后,就没有那个惊叹号咯!

  7. PyMysql复习

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

  8. poj1220------高精度进制转换模板

    #include<iostream> #include<cstdio> #include<cstring> using namespace std; const i ...

  9. tomcat安装配置常见问题详解

    历经波折,终于把tomcat装好了.记录下过程供自己和后来的初学者参考吧! 本文先后介绍了tomcat的下载安装方法.安装和启动不成功的常见原因 以及启动tomcat后如何配置上下文. 一.下载安装 ...

  10. Waiting for possible shutdown message on port 4445

    如果用jmeter通过命令行(无图形界面)执行测试脚本,可参见jmeter最简单使用,并且启动多个jmeter实例,肯定会报地址端口已占用: Waiting for possible shutdown ...