I have a list of numbers:
list = {1, 2, 3, 4, 5}
I want to create a function that calculates the factorial of each number in a list and prints it.
input_set = {1, 2, 3, 4, 5}
fact = 1
for item in input_set:
for number in range(1,item+1):
fact = fact * number
print ("Factorial of", item, "is", fact)
The output I get is:
Factorial of 1 is 1
Factorial of 2 is 2
Factorial of 3 is 12
Factorial of 4 is 288
Factorial of 5 is 34560
This is obviously wrong. I would really like to know what is wrong with my code and how to fix it.
Note. I do not want to use a function math.factorial
for this code.
source
share