#计算 num 的阶乘
def factorial(num):
i, multiply = 1, 1
while i < num+1:
multiply *= i
i += 1
yield multiply
if __name__ == '__main__':
# 生成器
user_input = input('请输入你需要计算的阶乘')
f = factorial(int(user_input))
while True:
try:
x = next(f)
except StopIteration as e:
print(x)
break
# 数学类
import math
print(math.factorial(int(user_input)))
来源:CSDN
作者:MonCasper
链接:https://blog.csdn.net/qq_43036676/article/details/103458141