Simple solution to 5/15


#1

I had a lot of trouble with this one as well, so I'm posting
my code as an example to help other beginners such as
me get a better understanding of how to do it. It was also
pretty similar to 4/15 if you've gotten this far.

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

#2

I have another one:

def factorial(x):
    fact = 1
    while x > 0:
        fact *= x
        x -= 1
    return fact


#3

I came up with this. It needed error checking for 0 and 1, which feels a bit like cheating, but the rest works great:

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