0

I tried to write a program to return he max number, however it returns none. I look into similar questions but I did't find the answer.

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()

silencefox
  • 69
  • 10

1 Answers1

0

Recursive functions need to return something under all conditions, you don't return anything under the else condition. Try return findMax(alist[1:]).

Bi Rico
  • 25,283
  • 3
  • 52
  • 75