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.
and this is my code
def FirstFactorial(num):
x = [1]
if num == 1:
return 1
else:
for i in range(1,num+1):
x = x*(i)
return x
print (FirstFactorial(4))
The expected output is 24. I get the following output from the code given above.
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
x = [1]rather thanx = 1? Factorials are not lists.