Python Practice Example 26
Question:Use recursion to find 5!.
Program analysis:Recursion formula: fn=fn_1*4!
Program source code:
Example
#!/usr/bin/python
# -*- coding: UTF-8 -*-
def fact(j):
sum = 0
if j == 0:
sum = 1
else:
sum = j * fact(j - 1)
return sum
print (fact(5))
The output of the above example is:
120Other extensions
Python 100 Examples