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. 程序的三大流程 在程序开发中,一共有三种流程方式: 顺序 —— 从上向下,顺序执行 ...
随机推荐
- java web代码规范:
每个类前要有注释,类前的注释格式是: /** *类是干什么的 *@author 编写该类的作者 */ 类中的每个方法前也要有注释: /** *该方法是干什么的 *@param 该方法中传入的参数 * ...
- MathJax $TeX$ Test Page
MathJax TeX Test Page When $a \ne 0$, there are two solutions to \(ax^2 + bx + c = 0\) and they are ...
- 设计模式之单件模式(Singleton Pattern)
一.单件模式是什么? 单件模式也被称为单例模式,它的作用说白了就是为了确保“该类的实例只有一个” 单件模式经常被用来管理资源敏感的对象,比如:数据库连接对象.注册表对象.线程池对象等等,这种对象如果同 ...
- 【加密算法】Base64
一.简介 Base64是网络上最常见的用于传输8Bit字节码的编码方式之一,Base64就是一种基于64个可打印字符来表示二进制数据的方法.可查看RFC2045-RFC2049,上面有MIME的详细规 ...
- javascript 对象克隆
浅克隆 先看代码: /** * 浅克隆 克隆传入对象,只克隆一层 * @param {any} source */ function shallowClone(source) { var tiaget ...
- laravel5的Bcrypt加密方式对系统保存密码的小结
laravel5文档介绍 //对 A 密码使用Bcrypt 加密 $password = Hash::make('secret'); //你也可直接使用 bcrypt 的 function $pass ...
- PageAdmin CMS网站建设教程:如何创建及管理栏目?
PageAdmin CMS网站制作教程:如何创建及管理栏目?1.登录管理后台后,在顶部导航中找到网站,并点击: 2.在左侧栏目中找到栏目管理,并点击: 3.进入到栏目管理页面,在顶部找到菜单,点击添加 ...
- day 82 Django Admin组件.
一.先建表环境 modules文件 from django.db import models # Create your models here. from django.contrib.auth.m ...
- PhoneGap - 解决用nmp无法安装PhoneGap问题!
PhoneGap从2.9.0开始,只采用node安装方式,安装命令如下: npm install -g phonegap 今天我使用此命令安装PhoneGap时候,始终无法安装,在网上搜索一下,最终解 ...
- 《Python绝技:运用Python成为顶级黑客》 用Python进行无线网络攻击
本章大部分代码都是实现了但是缺乏相应的应用环境,想具体测试的可以直接找到对应的环境或者自行修改脚本以适应生活常用的环境. 1.搭建无线网络攻击环境: 用Scapy测试无线网卡的嗅探功能: 插入无线网卡 ...