5/15 Why wont this work? Getting factorial(3) = 12, not 6


#1

Hi all, I feel like this code should work, but keep getting the following error message: Oops, try again. factorial(3) returned 12 instead of 6. Any help would be appreciated!

My Code:

digits = []
def factorial(x):
    while x > 0:
        for digit in str(x):
            digits.append(digit)
            x -= 1
    result = 1
    for digit in digits:
        result *= int(digit)
    return result


#2

digits = [] is not inside the function, so calling the function multiply times will mean digits will accumulate. Something you don't want


#3

Ahh it works now, thankyou!!


#4