Description
Have the function FirstFactorial(num)
take the num
parameter being
passed and return the factorial of it. For example: if num = 4, then your
program should return (4 * 3 * 2 * 1) = 24. For the test cases, the range will
be between 1 and 18 and the input will always be an integer.
My solutions
1
2
3
4
5
| def solution1(num):
first = 1
for factor in range(2, num + 1):
first *= factor
return first
|
1
2
3
4
| from functools import reduce
def solution2(num):
return reduce(lambda x, y: x * y, range(1, num + 1))
|