Python 查找最大数递归函数返回无?
我试图编写一个程序来返回最大值,但它不返回任何值。我研究了类似的问题,但没有找到答案Python 查找最大数递归函数返回无?,python,recursion,Python,Recursion,我试图编写一个程序来返回最大值,但它不返回任何值。我研究了类似的问题,但没有找到答案 def findMax(alist): if len(alist) == 1: return alist[0] else: if alist[0] > alist[1]: alist[1] = alist[0] findMax(alist[1:]) def main(): a = [1,3,4,2,6,7,9
def findMax(alist):
if len(alist) == 1:
return alist[0]
else:
if alist[0] > alist[1]:
alist[1] = alist[0]
findMax(alist[1:])
def main():
a = [1,3,4,2,6,7,9,12,3,20,4,32,5,6,9,10]
print(findMax(a))
main()。请尝试
返回findMax(列表[1:])