Factorial


#1

I cannot figure out why this code is not working. I know it mightnot be the most elegant, but it should provide the result
def factorial(x):
fac=0
if x==0 or x==1:
return 1
else:
for i in x:
fac=fac*i
return fac


#2

Great work on trying so far.

I think your for loop is problematic.

        for i in x:
            fac=fac*i

This would throw following error:

TypeError: 'int' object is not iterable

So, X is not a list, it's of type Integer. Hence you cannot iterate Integer through for loop.
So, think of a way how could you keep reducing the integer value and keep multiplying until you reach 1.