标签:lines lin 代码 llb pre += com continue color
1.理解和掌握while循环的使用
2.掌握break continue 控制语句
如下 :小明猜字游戏:
xiaoming_name = 20 name = int(input("请输入您要猜的年龄>>:")) if name > my_name : print("您猜错了,数字太大了") elif name < my_name : print("您猜错了,数字太小了") else: print(“恭喜你,猜对了”)
xiaoming_name = 20 num = 0 while num < 3: name = int(input("请输入您要猜的年龄>>:")) if name > my_name : print("您猜错了,数字太大了") elif name < my_name : print("您猜错了,数字太小了") else: print(“恭喜你,猜对了”) num += 1 else : print("游戏结束,谢谢")
count = 0 while count <= 100: #只要count小于100,就不断执行下面的代码 print("number",count) count += 1 #每执行一次,就把count + 1,避免变成死循环
10 % 2 8 % 2 #无余数,为整数 7 % 2 #有余数,是奇数
count = 0 while count <= 100: #只要count小于100就不断的执行下面的代码 if count % 2 == 0: #是偶数 print(“number”,count) count += 1 #每执行一次,就把count+1,避免变成死循环
count =0 while True: print("您好") count += 1
count = c 0 while count <= 100: #只要count <= 100,就不断执行下面的代码 print(“number”,count) if count == 3: break count += 1 #每执行一次,count就加1, print("------------welcome to you ------------------")
count = 0 while count <= 100: count += 1 if count > 10 and count < 80: continue print("number",count) print("------------welcome to you ------------------")
count = 0 while count <= 3: count += 1 print("number",count) else: print("正常执行完成") print("------------welcome to you ------------------")
count = 0 while count <= 3: count += 1 if count == 3: breaka print("number",count) else: print("正常执行完成") print("------------welcome to you ------------------")
标签:lines lin 代码 llb pre += com continue color
原文地址:https://www.cnblogs.com/FlameLuo/p/9612588.html