Factorial Help


This is my current code which is returning the following error message: "factorial(3) returned 8 instead of 6"

def factorial(x):
    if x==0 or x==1:
        return 1 
    elif x==2:
        return 2 
        total = x 
        while x >= 1:
            total = total * x-1
        return total


keep in mind order of operations, multiplying happens before subtracting. so this currently what is happening:

total * x
total -1

if you want to subtract one of x first use parentheses


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