Explanation needed


#1



def factorial(x):
    if x == 0 or x == 1:
        return 1
    else:
        return (x * factorial(x - 1))

(works) but how does this do factorial


#2

Factorial is when you multiply a number by one less over and over until you get to 1. For example: the factorial of 10 is 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1. If x is 0 there is no factorial, and if x is 1, the factorial is 1, so that's the first part of the statement. The second part is multiplying x by x - 1 over and over until x == 1.


#3

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