-1

I study recursive_function.

I think It have to print 120 ( 5 * * 4 * 3 * 2 * 1 )

but, It print 'None'

j = 1
def factorial(n):
    global j
    j = n * j
    n = n -1
    if n == 0:
        return j
    else:
        factorial(n)

print(factorial(5))
Silvio Mayolo
  • 62,821
  • 6
  • 74
  • 116

1 Answers1

1

You have to return when you make your recursive call. Rather than

factorial(n)

consider

return factorial(n)
Silvio Mayolo
  • 62,821
  • 6
  • 74
  • 116