Following is the code given for the factorial:

```
def factorial(x):
total = 1
while x>0:
total = total* x
x=x-1
return total
print(factorial(4))
```

output:24

At first the code I entered was,

```
def factorial(x):
total = 1
while x > 0:
total = total * x
x = x - 1
total = total * x #line 6
return total
print(factorial(4))
```

output:0

however, the line 6 was not needed which I understand. My problem is, the output for the first code gives the correct answer but the output for second code always gives 0.

I do not understand how the output becomes 0 when while loop explicitly has a condition x>0.

Please someone help me understand why. Thank You!