python中while循环语句

 

1、

>>> i = 1
>>> sum = 0
>>> while i <= 100:
    sum = sum + i
    i = i + 1        ## 当此处i等于101时循环停止

    
>>> print(sum)
5050

 

2、

>>> a = 100
>>> b = int(input("please input an num: "))
please input an num: 50
>>> while True:
    if b == a:
        break
    b = int(input("please input an num again: "))

    
please input an num again: 60
please input an num again: 200
please input an num again: 550
please input an num again: 100
>>> 

 

posted @ 2021-01-02 10:43  小鲨鱼2018  阅读(115)  评论(0编辑  收藏  举报