Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from functools import reduce
- from operator import mul
- def factorial(n):
- result = 1
- for x in range(1, n + 1):
- result *= x
- return result
- def factorial_reduce(n):
- return reduce(mul, range(1, n + 1))
- n = 5
- result1 = factorial(n)
- result2 = factorial_reduce(n)
- print('factorial(5) ==', result1)
- print('factorial_reduce(5) ==', result2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement