def factorial(x): """recursive factorial function""" #Base Case if x==0: ans = 1 #Recursion x! = x * (x-1)! else: print "factorial(" + str(x) + ") calling factorial(" + str(x-1) + ")" ans = x * factorial(x-1) print "factorial(" + str(x) + ") returning",ans return ans def reverseList(x): """reverse a list recursively""" #Base Case, a list with a single or no elements if len(x) <= 1: print "returning ",x return x #Recursion, reverse the tail of the list and append the head else: print "calling reverselist(",x[1:], ")" ans = reverseList(x[1:]) print "appending " + str(x[0]) + " to ", ans ans.append(x[0]) print "returning ", ans return ans