小编Dan*_*sch的帖子

递归函数类型错误

嗨我想尝试为Pascal三角形做一个递归函数来计算给定行中的特定值,下面是我的代码,我不断收到以下错误:

TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'
Run Code Online (Sandbox Code Playgroud)

我的代码到目前为止:

def recursive_pascal(i,j):      
   if i == 0:          
     return 1
   elif j == 1:          
     return 1
   else:
     recursive_pascal(i-1,j-1) + recursive_pascal(i-1,j)

print(recursive_pascal(3,2))
Run Code Online (Sandbox Code Playgroud)

python python-3.x

0
推荐指数
1
解决办法
312
查看次数

标签 统计

python ×1

python-3.x ×1