Skip to main content

We can combine the two functions to this single recursive function:

def factorial( n ): if n <1< 1: # base case return 1 else: returnNumber = n * factorial( n - 1 ) # recursive call print(str(n) + '! = ' + str(returnNumber)) return returnNumber 
def factorial( n ): if n <1: # base case return 1 else: returnNumber = n * factorial( n - 1 ) # recursive call print(str(n) + '! = ' + str(returnNumber)) return returnNumber 

We can combine the two functions to this single recursive function:

def factorial(n): if n < 1: # base case return 1 else: returnNumber = n * factorial(n - 1) # recursive call print(str(n) + '! = ' + str(returnNumber)) return returnNumber 
Source Link
pythonFoo
  • 2.2k
  • 3
  • 15
  • 17

def factorial( n ): if n <1: # base case return 1 else: returnNumber = n * factorial( n - 1 ) # recursive call print(str(n) + '! = ' + str(returnNumber)) return returnNumber