5/15 I completed the task,but I do not understand it

#1
``````  def factorial(x):
k= x-1
#stores numbers
if x==0:        #two if statments for uneeded
return 1

if x==1:
return 1

number = str(x)
for y in number:     # supposed to reduce

original_value= int(number)
the_factorial=original_value*factorial(x-1)
return the_factorial

print factorial(20)``````

I don"t understand why factorial(x-1) works

#2
``````def factorial(x):
list1 = []
result = 1
while x > 0:
list1.append(x)
x -= 1
else:
for i in list1:
result *= i
return result``````

That's how I solved it, maybe comparing the two might clear things up? looking at your code confuses me and it would take me a while to make sense of it, sorry. I rewrote my own code like 50 times, so ya

#3

This is what I used. The instructions say "to calculate the factorial of a non-negative integer x"
I suppose if you wanted to make sure it wasn't a negative number or a float, you could change to:

for i in range(1, int(abs(x)) + 1):

That would just convert it to a positive integer