Factorial(1) returned 0 instead of 1


I'm a bit lost here, what do I do?

My code:

def factorial(x):
    fact = 1
    while x > 0:
        fact = fact * x
        x -= 1
        return x


You are returning in the loop which breaks the loop and ends the function as soon as it hits. Move the return so it returns after the while loop. You are also returning x which will be 0 at the end of the loop. Return your fact variable.


Thanks! I got the indentation and error fixed


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.