DeaD_EyE

factorial

Nov 18th, 2018
114
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from functools import reduce
  2. from operator import mul
  3.  
  4. def factorial(n):
  5.     result = 1
  6.     for x in range(1, n + 1):
  7.         result *= x
  8.     return result
  9.  
  10. def factorial_reduce(n):
  11.     return reduce(mul, range(1, n + 1))
  12.  
  13.  
  14. n = 5
  15. result1 = factorial(n)
  16. result2 = factorial_reduce(n)
  17.  
  18. print('factorial(5) ==', result1)
  19. print('factorial_reduce(5) ==', result2)
RAW Paste Data