我刚开始在计划后学习python。递归是sum+=alist[0]+sumup(alist[1:])
不允许的吗?我得到错误
TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'
编码:
m=int(input())
c=list(map(int,input().split()))
x,y=map(int,input().split())
sum=0
def sumup(alist):
global sum
if alist==[]:
return 0
else:
if sum<x:
sum+=alist[0]+sumup(alist[1:])
elif sum>=x:
return sum
elif sum>y:
return 0
sumup(c)