def search(number, element, lista):
if number >= len(lista):
return "not find."
elif lista[number] == element:
return number
else:
search(number +1, element, lista)
r = search(0, 12, [2,5,1,6,8,12,24,3,7])
print(r)
答案 0 :(得分:0)
else
分支不会显式返回任何内容,因此它隐式返回None
。在此处添加一个return
,您应该可以:
def search(number, element, lista):
if number >= len(lista):
return "not find."
elif lista[number] == element:
return number
else:
return search(number +1, element, lista) # Here!