5/15 factorial.what's wrong with my code? thanks


#1

def factorial(x):
if x != 0:
y=1
total=1
while y total==total*y
y=y+1
return total
elif x==0:
return 1


#2

Perhaps it's more useful to ask how you may find the mistake yourself.
Try adding print statements and following along in what it does as it executes.
Also, if you want others to help you, you may find it much easier to get (good) replies if you explain your thoughts and ensure that the code that you post is intact.


#4

I did:

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


#5

heres a simpler version of code to solve for it.
def factorial(x):
total=1
while x>0:
total=total*x
x-=1
return total