Python Exercise Example 26
**Question:** Use recursion to find 5!.
**Program analysis:** Recursive 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
(
fact
(
5
)
)
The output of the above example is:
120
Python 100 Examples