Could someone please explain to me why my code isn't working properly?
I know that my solution is not elegant. I get this error message:
Oops, try again. factorial(4) returned 12 instead of 24
The goal is to create a function which calculates the factorial of x.
But when I print factorial(5) it prints 20
Thank you in advance.
def factorial(x): original = x while x is not 0: if x == original: factor = x x -= 1 else: factor *= x x -= x else: return factor print factorial(5)