-2

So I have a question that goes find the factorial of 25! and I am not allowed to use the math.facorial function.

So far I did

}} input()

}}}}25

and I was wondering is there anyway I can manipulate that to give me the factorial. Any help is appreciated.

jflow
  • 9
  • 1

2 Answers2

1

Here's without the math module:

>>> fact = 1
>>> for i in range(1, 26):
...     fact *= i
>>> fact
15511210043330985984000000

and with the math module:

>>> print(math.factorial(25))
15511210043330985984000000

fact *= i is the same as same fact = fact * i

0

You can create a recursive function (it calls itself within the function) and call that function with 25 as the input. you can use the logic as its definition: n! is the product of all positive integers less than or equal to n.

25! = 25 x 24!

24! = 24 x 23!

23! = 22 x 21!

...

...

2! = 2 x 1!

1! = 1 x 0!

0! = 1 (by definition, 0! is 1)

def myFactorialFunc(n):
  if n == 0:  #remember the definition 0! = 1
     return 1
  else:
     return n * myFactorialFunc(n-1)


result = myFactorialFunc(25)
print(result)