python:while 语句的使用方法

while语句:

count = 0
while True:
    print(count)
    count += 1
    if count == 10:
        break

实例:

计算n!,若:n = 5;则:n! = 5 * 4 * 3 * 2 * 1

#n!
n = int(input("输入n:"))
number = n
while True:
    if number == 1:
        break
    number = number * (n-1)
    n -= 1
    if n <= 2:
        break
print(number)

 

posted @ 2018-05-08 10:55  魁·帝小仙  阅读(4222)  评论(0编辑  收藏  举报