Python经典编程习题100例:第26例:递归求取阶乘

简介: Python经典编程习题100例:第26例:递归求取阶乘

题目描述:

利用递归方法求5!。

解题思路:

> 利用递归

代码:

def fn(n):
    if n==0 or n==1 :
        return 1
    return n*fn(n-1)
print(fn(5))


目录
相关文章
|
1天前
|
存储 Python
【python】习题第10周题解
【python】习题第10周题解
10 1
|
1天前
|
Python
【python】习题 第10周
【python】习题 第10周
7 0
|
1天前
|
Python
【python】习题第9周
【python】习题第9周
12 0
|
1天前
|
数据安全/隐私保护 Python
【python】习题第8周
【python】习题第8周
8 0
|
1天前
|
Python
【python】习题第7周(下)
【python】习题第7周(下)
11 0
|
1天前
|
自然语言处理 Python
【python】习题第7周(上)
【python】习题第7周(上)
12 1
|
1天前
|
Python
【python】习题 6-10周(下)
【python】习题 6-10周(下)
8 0
|
1天前
|
自然语言处理 数据安全/隐私保护 Python
【python】习题 6-10周(中)
【python】习题 6-10周(中)
14 0
|
1天前
|
Python
【python】习题 6-10周(上)
【python】习题 6-10周(上)
8 0
|
1天前
|
Python
【python】习题 1-5周(下)
【python】习题 1-5周(下)
9 0