Hey I'm new to lists and modules can you show me how to do this. I actually tried this code but it seems to be giving me a wrong answer
l = [1, 2, 3, 4, 5]
fact = 1 for i in l: for number in range(1,i 1): fact=fact*number print ("Factorial of", i, "is", fact)
CodePudding user response:
def factorial(n):
if n < 2:
return 1
else:
return n * factorial(n-1)
l = [1, 2, 3, 4, 5]
for number in l:
fact = factorial(number)
print("Facotrial of ",number," is",fact)
Here is a working example.
You can use the balise code to better show your code, I have trouble to read it so I can't really comment on what you did wrong
