pythonExample100/JCP026.py

17 lines
259 B
Python
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

'''
【程序26】
题目利用递归方法求5!。
1.程序分析递归公式fn=fn_1*4!
2.程序源代码:
'''
def fact(j):
sum = 0
if j == 0:
sum = 1
else:
sum = j * fact(j - 1)
return sum
for i in range(5):
print '%d! = %d' % (i,fact(i))