Is this a proper way to solve the factorial problem?


#1

I wrote this out to get the factorial of "x". I feel like it is not practical though, is it ok?

def factorial (x):
    number = x
    while x > 0:
        x -= 1
        if x >= 1:
            number *= x
        
    else:
        return number

??


#2

Well if this is the proper way? I don't know. :smiley:
But here is my code to solve this exercise, maybe you kind of get the idea and can improve it :slightly_smiling:

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