python中while
2019-04-04 11:46
176 查看
01.
“”"
while 条件():
条件1满足时,做的事情1
条件2满足时,做的事情2
“”"
#1.定义一个变量,记录循环次数 i = 1 #2.开始循环 while i <= 3: ##设定循环三次 #循环内执行的动作 print('hello python') #处理计数器 i += 1
02.while的死循环
while True: print('hello python')
03.while求和
求0到100所有整数的和
i = 0 result = 0 while i <= 100: result += i i += 1 print('和为:%d' %result)
04.while的嵌套
用whille的嵌套生成:
***** **** *** ** *
row = 5 while row >= 1: col = 1 while col <= row: print('*',end='') col += 1 print('') row -= 1
用while写出九九乘法表
row = 1 while row <= 9: col = 1 while col <= row: print('%d * %d = %d\t' %(row,col,col * row),end='') col += 1 print('') row += 1
猜数字游戏,五次机会
import random trycount = 0 computer = random.randint(1,100) while trycount < 5: player = int(input('Num:')) if player > computer: print('too big') trycount += 1 elif player < computer: print('too small') trycount += 1 else: print('恭喜') break print(computer)
相关文章推荐
- python 学习while语句中的break&continue
- python中的while循环解决简单的数学问题
- python分别用while和for于vcf格式提取复等位基因的snp(并计算分别条数)
- Python While 循环语句使用else语句
- 【Python基础】流程控制-while循环
- 【Python-3.3】使用while循环实现列表间数据移动
- python第二天 while if bool 等使用
- Python While循环语句 Python 编程中 while 语句用于循环执行程序,即在某条件下,循环执行某段程序,以处理需要重复处理的相同任务。其基本形式为: while 判断条件:
- python3 - while循环控制语句
- Python While循环语句
- python练习——用户输入与while循环
- Python学习笔记整理(十一)python的while和for循环
- Python03 if、while、for
- Python中的if、for、while、break练习题
- Python学习---用户输入和while循环
- python学习(十)赋值、表达式、if、while、for
- Python中for循环和while循环的基本使用方法
- python的for和while竟然有else语句,我石化了
- python中的while语句循环
- Python基础教程之if判断,while循环,循环嵌套