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. 程序的三大流程 在程序开发中,一共有三种流程方式: 顺序 —— 从上向下,顺序执行 ...
随机推荐
- ibatIs中的isNotNull、isEqual、isEmpty
isNull判断property字段是否是null,用isEmpty更方便,包含了null和空字符串 例子一:isEqual相当于equals,数字用得多些,一般都是判断状态值<isEqual ...
- FreeBSD查看即时网络流量
1.数据包 “netstat 1″一秒钟累计一次,”netstat 2″两秒钟累计一次.依此类推 2.查看网卡流量:”systat -if 1″每秒钟刷新一次,”systat -if 2″两秒钟刷新一 ...
- Grafana展示DNS解析延时
首先一个完整的监控肯定会包含三个部分:1.数据收集部分.2.数据存储部分.3.数据展示部分,今天我也是从这三个方面来实现这个监控的. 数据收集(SHELL 脚本) 没有想到比较好的方法来采集数 ...
- Jenkins中执行docker命令报错
Cannot connect to the Docker daemon. Is the docker daemon running on this host? 在配置Jenkins从Gitlab自 ...
- Quartz.net 的 FAQ
Quartz 是什么? Quartz 是作业调度系统,可以集成进其他软件系统.这里[作业调度程序]一词是指,在预定义时间执行(或通知)其他组件的系统. Quartz 有什么优点? 灵活,有多种使用方式 ...
- Alwayson--与复制的影响
在主副本上建立复制后,复制的事务日志读取代理(log reader)不会读取尚未同步到辅助副本的日志,因为辅助副本可能在下一时刻转化成为主副本,变为新的复制发布服务器,为此需要保证复制处理的日志总慢于 ...
- 基于Quartz.net的远程任务管理系统 一
在上一篇绪中,已经介绍了整个项目的情况下了,接下来就是开始一步步做起来了. 首先:先整个我们的Job任务表,以及Job执行日志表.SQL如下: drop table if exists job_inf ...
- Python: 读写Excel(openpyxl / win32com.client)
项目周报汇报的时候要做数据汇总,总是要从不同的excel文件中去获取数据最后汇总到一个excel表里面,所以决定用python直接写个自动化脚本来自动执行. 用python来读写excel,目前找了2 ...
- The rapid development platform upgrade, leave the time to yourself, the work is lost to the soft platform
Bring me back to your home. Please leave your work behind! Soft agile development framework V7.0 new ...
- 【cocos2d-x 手游研发----怪物智能AI】
原创文章,转载请注明出处:http://www.cnblogs.com/zisou/p/cocos2d-xARPG4.html 谈到怪物AI,我觉得就比较话多了,首先理解一下(Artificial I ...