day04流程控制之while循环
流程控制之while循环
1、什么是while循环
循环指的是一个重复做某件事的过程
2、为何有循环
为了让计算机能像人一样重复 做某件事
3、如何用循环
'''
# while循环的语法:while循环又称为条件循环,循环的次数取决于条件
'''
while 条件:
子代码1
子代码2
子代码3
'''
# print('start....')
# while True:
# name=input('please your name>>: ')
# pwd=input('please your password>>: ')
# if name == 'egon' and pwd == '123':
# print('login successful')
# else:
# print('user or password err')
# print('end...') # 如何结束while循环
# 方式一:操作while循环的条件让其结束
# print('start....')
# tag=True
# while tag:
# name=input('please your name>>: ')
# pwd=input('please your password>>: ')
# if name == 'egon' and pwd == '123':
# print('login successful')
# tag=False
# else:
# print('user or password err')
#
# print('end...') # 方式二: break强行终止本层循环
# count=1
# while count < 6:
# print(count)
# count+=1 # count=1
# while True:
# if count > 5:
# break
# print(count)
# count+=1 # print('start....')
# while True:
# name=input('please your name>>: ')
# pwd=input('please your password>>: ')
# if name == 'egon' and pwd == '123':
# print('login successful')
# break
# else:
# print('user or password err')
#
# print('end...') # 输错三次则退出
# 方式一:
# print('start....')
# count=0
# while count <= 2: #count=3
# name=input('please your name>>: ')
# pwd=input('please your password>>: ')
# if name == 'egon' and pwd == '123':
# print('login successful')
# break
# else:
# print('user or password err')
# count+=1
#
# print('end...') # 方式二
# print('start....')
# count=0
# while True:
# if count == 3:
# print('输错的次数过多傻叉')
# break
# name=input('please your name>>: ')
# pwd=input('please your password>>: ')
# if name == 'egon' and pwd == '123':
# print('login successful')
# break
# else:
# print('user or password err')
# count+=1
#
# print('end...') # while+continue:continue代表结束本次循环,直接进入下一次
# count=1
# while count < 6:
# if count == 4:
# count+=1
# continue # 只能在cotinue同一级别之前加代码
# print(count)
# count+=1
#
#
# while True:
# print('11111')
# print('22222')
# print('333')
# continue # 不应该将continue作为循环体最后一步执行的代码 # while+else
# count=1
# while count < 6:
# if count == 4:
# break
# print(count)
# count+=1
# else:
# print('会在while循环没有被break终止的情况下执行') # 输错三次则退出之while+else的应用
# print('start....')
# count=0
# while count <= 2: #count=3
# name=input('please your name>>: ')
# pwd=input('please your password>>: ')
# if name == 'egon' and pwd == '123':
# print('login successful')
# break
# else:
# print('user or password err')
# count+=1
# else:
# print('输错的次数过多')
#
# print('end...') # while循环的嵌套
# name_of_db='egon'
# pwd_of_db='123'
# print('start....')
# count=0
# while count <= 2: #count=3
# name=input('please your name>>: ')
# pwd=input('please your password>>: ')
# if name == name_of_db and pwd == pwd_of_db:
# print('login successful')
# while True:
# print("""
# 1 浏览商品
# 2 添加购物车
# 3 支付
# 4 退出
# """)
# choice=input('请输入你的操作: ') #choice='1'
# if choice == '1':
# print('开始浏览商品....')
# elif choice == '2':
# print('正在添加购物车....')
# elif choice == '3':
# print('正在支付....')
# elif choice == '4':
# break
# break
# else:
# print('user or password err')
# count+=1
# else:
# print('输错的次数过多')
#
# print('end...') # tag控制所有while循环
name_of_db='egon'
pwd_of_db='123'
tag=True
print('start....')
count=0
while tag:
if count == 3:
print('尝试次数过多')
break
name=input('please your name>>: ')
pwd=input('please your password>>: ')
if name == name_of_db and pwd == pwd_of_db:
print('login successful')
while tag:
print("""
1 浏览商品
2 添加购物车
3 支付
4 退出
""")
choice=input('请输入你的操作: ') #choice='1'
if choice == '1':
print('开始浏览商品....')
elif choice == '2':
print('正在添加购物车....')
elif choice == '3':
print('正在支付....')
elif choice == '4':
tag=False else:
print('user or password err')
count+=1 print('end...')
day04流程控制之while循环的更多相关文章
- SSIS从理论到实战,再到应用(4)----流程控制之For循环
原文:SSIS从理论到实战,再到应用(4)----流程控制之For循环 上期回顾: SSIS从理论到实战,再到应用(3)----SSIS包的变量,约束,常用容器 在SSIS体系中,控制流可能经常会遇到 ...
- SSIS从理论到实战,再到应用(5)----流程控制之Foreach循环
原文:SSIS从理论到实战,再到应用(5)----流程控制之Foreach循环 上期回顾: SSIS从理论到实战,再到应用(4)----流程控制之For循环 上一期讲了For循环,Foreach循环相 ...
- [转帖]流程控制:for 循环
流程控制:for 循环 http://wiki.jikexueyuan.com/project/linux-command/chap34.html need more study need more ...
- php总结3——基本函数、流程控制中的循环
3.1 php基本函数(数学.日期.字符串) 数学函数:max mixed max(number $arg1,number $arg2,……) 求一组数据中的最大值 m ...
- 流程控制之while循环for循环
流程控制之while循环1.什么是循环 循环就是重复做某件事2.为什么要有循环 为了让计算机能够具备人重复做某件事的能力3.如何用循环 while语法: while 条件: code1 code2 c ...
- 流程控制之 for 循环
目录 流程控制之for循环 for 循环条件语句 for 循环的嵌套 流程控制之for循环 for 循环条件语句 for i in range(3): print(i) # 0 # 1 # 2 for ...
- day04流程控制,if分支结构,while,for循环
复习 ''' 1.变量名命名规范 -- 1.只能由数字.字母 及 _ 组成 -- 2.不能以数字开头 -- 3.不能与系统关键字重名 -- 4._开头有特殊含义 -- 5.__开头__结尾的变量,魔法 ...
- Day04 流程控制 while 和for循环
一.流程控制 if 判断 python中使用缩进来区分代码块的 语法 一: #python if 条件: 代码块1 代码块2 自上而下依次运行 语法二: # python if 条件一: 代码一 el ...
- day04 流程控制
在python中流程控制主要有三种:顺序流程.分支流程.循环流程 1.顺序流程:在宏观上,python程序的运行就是自上而下的顺序流程: 2.分支流程:分支流程主要是 if...else....流程 ...
随机推荐
- 《剑指offer》第四十六题(把数字翻译成字符串)
// 面试题46:把数字翻译成字符串 // 题目:给定一个数字,我们按照如下规则把它翻译为字符串:0翻译成"a",1翻 // 译成"b",……,11翻译成&qu ...
- 学习笔记17—circos安装集(window环境)
Windows7环境下Circos使用教程 一.下载安装软件包 1.strawberry perl 因为Circos软件是依赖perl语言编译环境的,但是windows环境下默认是没有perl的,所以 ...
- ssh REMOTE HOST IDENTIFICATION HAS CHANGED!
连接到docker的时候,有时因为image重新buid过,就提示 It is also possible that a host key has just been changed. 不让连接. 解 ...
- MySQL学习(十四)
utf8的bom问题 在xp下,用记事本创建utf8文件的时候,前面多了3个字节,这3个字节不用来显示,是用来辨识编码用的,EF BB BF告诉记事本,这是utf8编码. 存储引擎和事务简单介绍 引擎 ...
- QT绘制饼图
QT版本:QT5.6.1 QT绘制饼图,出问题的代码如下 void DrawPieDialog::paintEvent(QPaintEvent *event) { float startAngle=0 ...
- 单调队列 Monotonic Queue / 单调栈 Monotonic Stack
2018-11-16 22:45:48 一.单调队列 Monotone Queue 239. Sliding Window Maximum 问题描述: 问题求解: 本题是一个经典的可以使用双端队列或者 ...
- Access大数据高效分页语句
Access大数据高效分页语句 oracle的分页查询可以利用rowid伪列. db2的分页查询可以利用row_number() over()聚合函数. mysql有limit. access仿佛先天 ...
- PC端、移动端的页面适配及兼容处理
转自 一.关于移动端兼容性 目前针对跨终端的方案,主要分为两大阵营:一套资源Vs两套资源. 第一种是通过响应式或页面终端判断去实现一套资源适配所有终端: 第二种是通过终端判断分别调取两套资源以适配所有 ...
- Servlet Exception and Error Handling
Servlet API support for custom Exception and Error Handler servlets that we can congiure in deployme ...
- java ----> 基础之位运算
package test.ant; import java.util.Arrays; import java.io.UnsupportedEncodingException; public class ...