Write a python program to find factorial, use exception handling and display an appropriate message if the user inputs alphabets instead of the number. Emulate Index error for a list and handle that exception. Find factorial for all numbers in a given list and display the result.

Respuesta :

def func(lst):

   fac_lst = ([])

   try:

       for x in lst:

           i = 0

           fac = 1

           while i < x:

               fac *= (x - i)

               i += 1

           fac_lst.append(fac)

       return fac_lst

   except TypeError:

       return "Please input only numbers!"

   except IndexError:

       return "Please stay within the index!"

lst = ([1, 2, 3, 4, 5, 6, 7, 8])

print(func(lst))

I think this is what you're looking for. Best of luck.