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. 程序的三大流程 在程序开发中,一共有三种流程方式: 顺序 —— 从上向下,顺序执行 ...
随机推荐
- VS2010与Qt5.1.0的集成
早就听说qt可以集成到VS中,就是一直没尝试过.一直在使用qt creator,也没觉得它有什么不好.可最近VS用多了,我发现一个qt creator中很不好的毛病,就是代码自动完成时,creator ...
- LeetCode142:Linked List Cycle II
题目: Given a linked list, return the node where the cycle begins. If there is no cycle, return null. ...
- Android开发消除横向排列的多个Button之间的空隙
一.问题重述 摘要里描述的可能不太清楚,问题如下图: 如何消除Button1和Button2之间的空隙,以及Button与左右边界之间的空隙? 二.问题根源 这里出现的空隙其实是Button的背景图片 ...
- AI_ 视频监控-人体移动捕捉监测
总目录地址:AI 系列 总目录 需要最新源码,或技术提问,请加QQ群:538327407 我的各种github 开源项目和代码:https://github.com/linbin524 需求 为了实现 ...
- Disruptor使用简介
disruptor是lmax公司开发的一款java高性能并发框架,其本质是一种类似队列的实现“生产者—消费者 ”模式的组件. 下面是其示例代码: public class DisruptorServe ...
- linux系统下安装Jenkins
1.首先准备java环境,安装JDK 2.部署jenkins wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redha ...
- 预处理函数在app和蓝图级别的不同使用
app级别 from flask import Flask from flask_sqlalchemy import SQLAlchemy # SQLAlchemy 类实例对象的创建一定要在引用蓝图之 ...
- flask组件之flask_script和flask_migrate的使用
flask_script的使用 作用: 使用命令启动flask项目 # 在项目的启动文件中 from flask import Flask from settings import Settings ...
- 双向链表的实现——java
实现类: /** * Java 实现的双向链表. * 注:java自带的集合包中有实现双向链表,路径是:java.util.LinkedList * * @author skywang * @date ...
- mysql 数据备份 crontab
每天凌晨 2 点备份数据 crontab -e 0 2 * * * mysqldump ${mysqldir}/bin/mysqldump -h$host -P$port -uadmin -p&qu ...