Code not working 5.factorial


def factorial(x):
    while m>0:
        return t
        return 1


Much simpler to do this:

def factorial1(n):
    if n < 2: 
        return 1
    return n * factorial(n-1)

You see, factorial 0 and 1 both equal to 1, so this line takes care of that:

 if n < 2:

Then any other factorial is take care of by doing this:

  return n * factorial(n-1)

Hope that helps! :slight_smile:

-- @chipjumper36731


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