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. 发个招聘贴,魔都求手游C++后端,UNITY前端,开发实习生

    上海游旺网络科技有限公司成立于2015年5月,是一家极具潜力的新创移动游戏公司.公司初创团队均来自腾讯,盛大,畅游,墨麟,蜗牛等知名互联网公司,公司创始人团队参与制作过<鬼吹灯><Q ...

  2. Android-Java-Thread的使用

    main线程跑三个任务: package android.java.thread2; class Demo { private String name; public Demo(String name ...

  3. .netcore部署centos

    前言:最近公司有个项目用 .netcore开发的项目,然后闲的没事就研究如果发布到Linux系统上 需要安装的插件以及支撑架构 1.dotnetSDK 2.jexus Jexus 是Linux平台上 ...

  4. C# Lock锁(个人随记)

    先看看为什么要用锁 需求:多线程处理值的加减   static int NoLockData = 0; public static void NoLockNormalTest(int threadIn ...

  5. sql server生成自动增长的字母数字字符串

    在开发的过程中,我们经常会遇到要生成一些固定格式字符串,例如“BX201903150001”,结构为:BX+日期+N位序号,类似这种的字符串我们很难生成,在这里我们借助一个存储过程来实现这个功能. 1 ...

  6. ABP框架入门踩坑-使用MySQL

    使用MySQL ABP踩坑记录-目录 起因 因为我自用的服务器只是腾讯云1核1G的学生机,不方便装SQL Server,所以转而MySQL. 这里使用的MySQL版本号为 8.0. 解决方案 删除Qi ...

  7. AtomicBoolean

    它的两种用法: 1.保证某段语句只执行一次. 首先我们要知道compareAndSet的作用,判断对象当时内部值是否为第一个参数,如果是则更新为第二个参数,且返回ture,否则返回false.那么默认 ...

  8. openvswitch BFD 简介

    为了保护关键应用,网络中会设计有一定的冗余备份链路,网络发生故障时就要求网络设备能够快速检测出故障并将流量切换至备份链路以加快网络收敛速度.目前有些链路(如POS)通过硬件检测机制来实现快速故障检测. ...

  9. CRUD组件的高阶使用

    1.list页面自定列显示: class PermissionConfig(sites.AryaConfig):       def dabo(self, obj=None, is_header=Fa ...

  10. elasticsearch 5.x Delete By Query API(根据条件删除)

    之前在 2.X版本里 这个Delete By Query功能被去掉了 因为官方认为会引发一些错误 如需使用 需要自己安装插件. bin/plugin install delete-by-query 需 ...