,计数器加1
while...else....语法
#!/usr/bin/env python #-*- coding:utf-8 _*- """ @author:chenjisong @file: guess.py @time: 2019/04/16 url:https://www.liaoxuefeng.com functions: Software:JetBrains PyCharm 4.5.3 """ Name_Of_Oldboy = 56 count = 0 while count < 3: guess_age = int(input("please input your guess number:")) if guess_age == Name_Of_Oldboy: print("Yes,you got it.") break elif guess_age > Name_Of_Oldboy: print("think smaller.") else: print("think bigger.") count += 1 else: print("you have tried too many times!!!") 解释:当尝试的次数小于3的时候,走上面的代码。 当尝试的次数大于3的时候,打印 you have tried too many times
第一周-第13章节-Python3.5-while 循环优化版本
#!/usr/bin/env python #-*- coding:utf-8 _*- """ @author:chenjisong @file: for.py @time: 2019/04/16 url:https://www.liaoxuefeng.com functions: Software:JetBrains PyCharm 4.5.3 """ Name_Of_Oldboy = 56 count = 0 for i in range(3): guess_age = int(input("please input your guess number:")) if guess_age == Name_Of_Oldboy: print("Yes,you got it.") break elif guess_age > Name_Of_Oldboy: print("think smaller.") else: print("think bigger.") else: print("you have tried too many times!!!")
####任性玩:
#!/usr/bin/env python #-*- coding:utf-8 _*- """ @author:chenjisong @file: while.py @time: 2019/04/16 url:https://www.liaoxuefeng.com functions: Software:JetBrains PyCharm 4.5.3 """ Name_Of_Oldboy = 56 count = 0 #for i in range(3): while count < 3: guess_age = int(input("please input your guess number:")) if guess_age == Name_Of_Oldboy: print("Yes,you got it.") break elif guess_age > Name_Of_Oldboy: print("think smaller.") else: print("think bigger.") count += 1 if count == 3: continue_confirm = input("do you want to keep guessing...?") if continue_confirm != "N": count = 0 解释:当三次猜数都没有猜对且次数大于3时发出继续的确认信息,如果输入N,就退出,如果输入其他任意键,继续
第一周-第14章节-Python3.5-for 循环及作业要求
continue:跳出本次循环进行下一次循环 break :跳出整个循环
#!/usr/bin/env python #-*- coding:utf-8 _*- """ @author:chenjisong @file: chengfakoujue.py @time: 2019/04/16 url:https://www.liaoxuefeng.com functions:乘法口诀表 Software:JetBrains PyCharm 4.5.3 """ for i in range(1,10): for j in range(1,i+1): print("%d * %d = %2d" % (j,i,j*i),end=" ") print (" ")
========================================================================
G:\Python3.7.3\python.exe G:/practise/oldboy/day1/chengfakoujue.py 1 * 1 = 1 1 * 2 = 2 2 * 2 = 4 1 * 3 = 3 2 * 3 = 6 3 * 3 = 9 1 * 4 = 4 2 * 4 = 8 3 * 4 = 12 4 * 4 = 16 1 * 5 = 5 2 * 5 = 10 3 * 5 = 15 4 * 5 = 20 5 * 5 = 25 1 * 6 = 6 2 * 6 = 12 3 * 6 = 18 4 * 6 = 24 5 * 6 = 30 6 * 6 = 36 1 * 7 = 7 2 * 7 = 14 3 * 7 = 21 4 * 7 = 28 5 * 7 = 35 6 * 7 = 42 7 * 7 = 49 1 * 8 = 8 2 * 8 = 16 3 * 8 = 24 4 * 8 = 32 5 * 8 = 40 6 * 8 = 48 7 * 8 = 56 8 * 8 = 64 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
Process finished with exit code 0
作业:一.博客
二.编写登录接口
1.输入用户名密
2.认证成功后显示欢迎信息
3.输错三次后锁定
三、多级菜单 1.三级菜单 2.可依次选择进入各子菜单 3.所需知识点,列表,字典
|