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 <= 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嵌套循环的更多相关文章
- Python For嵌套循环 图形打印X型 nested loop -练习题
For嵌套循环图形打印作业很多是C++语言做的,我觉得Python应该也能做,就来试一试. 原网址C++练习题:http://www.imooc.com/qadetail/216848?t=33880 ...
- Python For嵌套循环 图形打印X型 nested loop - 练习题答案
上一篇:Python For嵌套循环 图形打印X型 nested loop - 练习题 上一篇留的Python For嵌套循环 图形打印X型练习题的答案. 由于网上很多嵌套循环都是C++语言写的,用P ...
- [Python] For 嵌套循环打印图形 nested loop-练习题答案
前一篇:[Python] For 嵌套循环打印图形 nested loop-练习题 [python的for循环嵌套打印如下图形] 图形一: 输出结果: ******* ******* ******* ...
- [Python] For 嵌套循环打印图形 nested loop - 练习题
[python的for循环嵌套打印如下图形] 图形一: ******* ******* ******* ******* 图形二: * *** ***** ******* 图形三: * *** **** ...
- python 跳出嵌套循环方法
class LoopError(Exception):pass rs = '' try: for i in range(1, 3): print i rs = 'one ' if i == 1: fo ...
- [Python]循环嵌套nested loop-练习题
[python的for循环嵌套打印如下图形] 图形一: ******* ******* ******* ******* 图形二: * *** ***** ******* 图形三: * *** **** ...
- python使用笔记
修改文件模板,支持中文. File -> Settings -> Editor -> File and Code templates -> python Scropt 在里面加 ...
- python基础-循环语句for\嵌套循环
for循环格式: for index in range(0,3):#等同于range(3),取0\1\2 print(index) index = 0 starnames = ['xr1','xr2' ...
- 一文了解Python中的循环(for while break continue 嵌套循环...)
循环 目标 程序的三大流程 while 循环基本使用 break 和 continue while 循环嵌套 01. 程序的三大流程 在程序开发中,一共有三种流程方式: 顺序 —— 从上向下,顺序执行 ...
随机推荐
- [ASP.NET]JQuery直接调用asp.net后台WebMethod方法
在项目开发碰到此类需求,特此记录下经项目验证的方法总结. 利用JQuery的$.ajax()可以很方便的调用asp.net的后台方法. [WebMethod] 命名空间 1.无参数的方法调用 注意:方 ...
- vs2017新建.netcore相关项目提示"未检测到任何.NET Core SDK"或打开.net core 相关项目Web层总是未能正常加载
近来vs2017出现一个非常怪的现象,之前新建.net core相关项目好好的,现在出现问题,如下: 解决办法,是更新vs2017,界面如下:
- 统一登录中心SSO 单点登录系统的构想
什么是单点登录?我想肯定有一部分人“望文生义”的认为单点登录就是一个用户只能在一处登录,其实这是错误的理解.单点登录指的是多个子系统只需要登录一个,其他系统不需要登录了(一个浏览器内).一个子系统退出 ...
- C# autofac配置文件中设置单例
设置instance-scope属性值为SingleInstance
- L-BFGS算法介绍
可以看出,拟牛顿法每次迭代只需要根据前次迭代的即可以计算出,不需要求出Hesse矩阵的逆. 2.4 L-BFGS(limited-memory BFGS) BFGS算法中每次迭代计算需要前次迭代得到的 ...
- jzoj5806
我們發現,如果有奇環顯然無解,因為我們每一次合併一個奇環,一定會產生一個偶環和一個更小的奇環,最終會形成一個三元環而無法合併 所以,這個圖需要是一個二分圖,需要進行二染色 然後把這個圖所有的偶環找出來 ...
- nginx代理websocket协议
以下是代码段.location /wsapp/ { proxy_pass http://wsbackend; proxy_http_version 1.1; proxy_set ...
- 恢复xfs文件系统superblock实验
1. 创建一个XFS文件系统[root@localhost ~]# mkfs.xfs -f /dev/vdb1meta-data=/dev/vdb1 isize=256 ...
- 利用Django和装饰器做一个简单的修改密码页面
view视图代码: from django.shortcuts import render,redirect from django.http import HttpResponse from PIL ...
- WebDriverAPI(6)
在指定元素上方进行鼠标悬浮 测试网址 http://www.baidu.com Java语言版本实例 @Test public void roverOnElement() { driver.manag ...