Python程序求阶乘

2024-11-27 00:37:09
推荐回答(1个)
回答1:

def little_than_50(x):
    if x <= 50:
        return True
    else:
        return False

def calculate_factorial(x):
    if x <= 1:
        return 1
    else:
        return x*calculate_factorial(x-1)
while True:
    n = int(input("Input a number for calculating factorial:"))
    if little_than_50(n):
        break
    else:
        print("{} is out of range,please input again!".format(n))
print("The factorial of {} is {}".format(n, calculate_factorial(n)))