python#原创第13篇~while循环+答案
来源:互联网 发布:风居住的街道 知乎 编辑:程序博客网 时间:2024/05/21 09:19
2017-12-02 12:36:35 December Saturday the 48 week, the 336 day#原创第13篇~while循环#普通whilenum = 1 #num is numberwhile num <= 3: #while执行后面语句块 print(num) #每次循环让num加1 num += 1 #等价于num = num +12017-12-02 12:36:39 December Saturday the 48 week, the 336 day#原创第13篇~while循环#while和input函数robote = "\nplease talk to me, and I will repeat what you say:"robote += "\nEnter 'Q' to end the program.\n" #用户输入Q程序结束words = ""while words != 'Q': words = input(robote) print(words)2017-12-02 13:04:09 December Saturday the 48 week, the 336 day#原创第13篇~while循环#while和else语句num = 1 #num is numberwhile num <= 3: #while执行后面语句块 print(num) #每次循环让num加1 num += 1 #等价于num = num +1else: print("num is not less than 3") #num 不再小于数字3了#只有当while为假,全部执行完成后才执行else后面的语句。2017-12-02 13:44:32 December Saturday the 48 week, the 336 day#原创第13篇~while循环#while和break语句k = 1while 1: # 循环条件为1必定成立 if k > 5: # 当i大于5时跳出循环 break #k为6时候跳出while循环,不再输出k的值 print(k) # 输出1~5 k += 1 #每循环一次,让k的值加1,等价于:k = k + 12017-12-03 17:59:59 December Sunday the 48 week, the 337 day#原创第13篇~while循环#while and continue'''i是奇数时,if条件成立,接着执行continue,接着跳过print(i)函数,返回去重新执行while条件语句i < 10i是偶数时候,if语句不成立,跳过continue语句,执行print(i),然后返回去重新执行while条件语句i < 10'''i = 1while i < 10: i += 1 if i%2 > 0: continue # print(i) # 输出双数2、4、6、8、102017-12-03 18:44:49 December Sunday the 48 week, the 337 day#原创第13篇~while循环#while和true and false语句robote = "\nplease talk to me, and I will repeat what you say:"robote += "\nEnter 'quit' to end the program.\n" #用户输入Q程序结束condition = Truewords = ""while condition: words = input(robote) #words得到输入的字符 if words == "quit": condition = True #用户一旦输入quit,while循环就结束 else: print(words) #只要用户没有输入quit,就一直输出输入的内容2017-12-03 19:02:13 December Sunday the 48 week, the 337 day#原创第13篇~while循环#控制台运行python程序,ctrl + C 结束 while死循环while 1: #条件始终成立,while将会被一直执行 print("I love Python") #唯有Ctrl + C 让我不会再爱python2017-12-03 20:02:13 December Sunday the 48 week, the 337 day#原创第13篇~while循环#课后题:99乘法口诀i=1 #i是行数while i<=9: #外边一层循环控制行数 j=1 #j是列数 while j<=i: #里面一层循环控制每一行中的列数 nine_nine =j*i print("%d*%d=%d"%(j,i,nine_nine), end=" ") #print(" ") j+=1 print(i,"行结束") #print("") i+=11*1=1 1 行结束1*2=2 2*2=4 2 行结束1*3=3 2*3=6 3*3=9 3 行结束1*4=4 2*4=8 3*4=12 4*4=16 4 行结束1*5=5 2*5=10 3*5=15 4*5=20 5*5=25 5 行结束1*6=6 2*6=12 3*6=18 4*6=24 5*6=30 6*6=36 6 行结束1*7=7 2*7=14 3*7=21 4*7=28 5*7=35 6*7=42 7*7=49 7 行结束1*8=8 2*8=16 3*8=24 4*8=32 5*8=40 6*8=48 7*8=56 8*8=64 8 行结束1*9=9 2*9=18 3*9=27 4*9=36 5*9=45 6*9=54 7*9=63 8*9=72 9*9=81 9 行结束[Finished in 0.4s]
阅读全文
0 0
- python#原创第13篇~while循环+答案
- 原创第13篇~while循环
- 第13课 Python中while循环
- python原创第十四篇~判断,循环实战训练+答案
- python连载第12篇 for循环 源码+ 答案
- 第33个python程序:while循环
- 第28课 Python的while循环与文件
- Python基础篇之while循环
- Python的while循环
- Python While循环语句
- python while循环控制
- python中的while循环
- python while循环
- python while循环
- Python--While循环语句
- python--while循环
- Python之While循环
- Python while 循环
- 自动称重系统-1
- JSP开发模式笔记
- LinkedIn 全球副总裁:如何搭建一个 5 亿用户的职场社区
- 35. Search Insert Position
- [Ahoi2013]差异 后缀自动机
- python#原创第13篇~while循环+答案
- 玩转JVM虚拟机:JVM内存结构
- iscsi
- 1*2*3.....*n的值
- Curator之异步接口。
- python 实现插入排序,冒泡排序,快速排序,选择排序
- 判断奇偶数
- 解决前台传入参数乱码问题
- 解决80端口被system占用