While 循环
语法结构
1 while 判断条件: 2 执行语句…… 3 4 #while 语句的用法 5 while True : 6 print("loop")
简单的例子:
目标:打印 0-9的数字
count = 0 while count < 10: count += 1 print("count number:",count)
练习:
1、打印1-100的偶数
count = 0 while count <=100 : if count % 2 == 0 : print("count number:",count) count += 1
2、循环打印1-100,第50不打印,第60-80次,打印对应的平方值
count = 0 while count <= 100 : count += 1 if count <= 49 : print("count number:",count) elif 60<= count <= 80 : print("number:" ,count*count) elif count > 80 and count <= 100: print("count number:",count)
3、猜年龄游戏
作业!