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]

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 睾丸发育不完全精子存活率低怎么办 踢到睾丸很痛怎么办 兔子的睾丸烂了怎么办 梗阻性无精穿刺取得精子不好怎么办 甲状腺做完穿刺后是恶性怎么办 硬了之后睾丸痛怎么办 腋下胯间颜色深怎么办 当兵前上班有社保怎么办 别人背后害我我怎么办 左侧胸明显大于右侧胸怎么办 婴儿拉大便次数多怎么办 公鸽子不会踩蛋怎么办 生殖器套东西取不下来怎么办 婴儿成蛋蛋的皮好长怎么办 丈夫总要害自己该怎么办 脚背踢肿了怎么办很疼 踢沙袋脚背伤了怎么办 脚y子烂了怎么办 掐喉咙那会痒会咳嗽怎么办 掐到婴儿脖子了怎么办 孩子胳膊不小心烫破皮了怎么办 孩子嘴角磕破了怎么办 电话不小心拒接了怎么办 手机微信不小心碰到语言英文怎么办 手机微信不小心碰到英文说话怎么办 不小心碰到宝宝卤门怎么办 不小心碰到婴儿头顶囟门怎么办 重要部位被踢了怎么办 吃了带刺的葡萄怎么办 小孩子老是去厕所大便怎么办 家人偷了我的钱怎么办 小孩打闹踢到要害怎么办 腿上汗毛孔没开都是点点怎么办 脸蛋澡巾擦破了怎么办 婴儿后背用擦澡巾擦红了怎么办 搓澡皮肤搓破了怎么办 搓背搓的脖子红痒怎么办 上班迟到1个小时怎么办 想家想的都哭怎么办 想学手艺被骗学费怎么办 小腿肚后面筋和肌肉压痛怎么办