24 不会做了

编写一个函数,用于计算n!(其中n!=1*2*3*···*n),并计算20!的值。
求答案


请先 登录 后评论

最佳答案 2021-09-23 23:08

用递归

  1. def fac(x):
  2.     if x==1:
  3.         return x
  4.     else:
  5.         return x*fac(x-1)
复制代码
请先 登录 后评论

其它 3 个回答

帅哥淦
  1. def ccd(a):
  2.     num = 1
  3.     for i in range(1,a+1):
  4.         num *= i
  5.     return print(num)
  6. ccd(20)
复制代码


请先 登录 后评论
乡下女孑
import operator
from functools import reduce

n = 20
result = reduce(operator.mul, range(1, n+1))
print(result)
请先 登录 后评论
时榕-余
  1. import math
  2. n = 20
  3. result = math.factorial(n)
复制代码
请先 登录 后评论
  • 4 关注
  • 0 收藏,338 浏览
  • Swine 提出于 2021-09-23 23:08

相似问题