python:while 语句的使用方法

while语句:

count =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)

相关推荐