Lesson 1#11 循环

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)
View Code

 

练习:

1、打印1-100的偶数

count = 0
while count <=100 :
    if count % 2 == 0 :
        print("count number:",count)
    count += 1
View Code

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)
View Code

 3、猜年龄游戏

作业!
posted @ 2018-03-07 21:58  WudTime  阅读(121)  评论(0编辑  收藏  举报