Factorial of a large number in python

后端 未结 9 831
灰色年华
灰色年华 2020-12-29 12:32

Here\'s my approach to factorials:

def factorial(n):
    \'\'\'Returns factorial of n\'\'\'
    r = 1
    for i in range(1, n + 1):
        r *= i
    return         


        
9条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-29 13:26

    You can return the gamma function (math.gamma(x)), but it would probably be faster to generate the factorial with a for loop

提交回复
热议问题