Need help 15.5 Factorial


I'm trying to create a list of everything that needs to be multiplied to get the factorial, and then multiply each item in that list by the next. I keep getting the error "factorial(1) returned [1, 0] instead of 1"

def factorial(x):
    y = [x]
    for number in y:
        number -= 1
        return y
        for number in y:
            product = 1
            product *= number
            return product


Why choose you that difficult and not optimal way to solve this problem? Is not better using for loop with negative step (positive can be also because not matter which side we start multiple :D) ? :slight_smile:

def factorial(x):
    score = 1
    for i in range(x,1,-1):
        score *= i
    print (score)
    return score


Ps. Your function is wrong because your first for loop works only one time because for the beggining of loop you give only one argument (that is list with one element).
Btw. Inside your loop you add second argument ussing (.append()), so the final score is the list with two elements :wink: