Write a function factorial_list(Arr) in Python, which accepts a list Arr of numbers and return the list of factorial of each value

Output Example:-

Sample Input Data of the list: Arr= [1,2,3,4,5]
Sample Output Data in the List: Op = [1,2,6,24,120]

Edit*= sorry forgot to give what have i done so far:-

def factorial_list(Arr):
    for item in Arr:
        fact = 1
    for number in range(1,item+1):
        fact = fact * number
        print ("Factorial of", item, "is", fact)
l1=eval(input("Enter List: "))
factorial_list(l1)

here is my output:

Enter List: [1,2,3,4,5]
Factorial of 5 is 1
Factorial of 5 is 2
Factorial of 5 is 6
Factorial of 5 is 24
Factorial of 5 is 120

which is not my desired output what should I do to get it in my list form??

>Solution :

import math

def factorial_list(Arr):
    ret = []
    for el in Arr:
        ret.append(math.factorial(el))
    return ret

l1=eval(input("Enter List: "))
print('Factorials:', factorial_list(l1))

Output:

Enter List: [1, 2, 3, 4, 5]
Factorials: [1, 2, 6, 24, 120]

Leave a Reply