#recursive routine to sum a list of numbers #program sumList (recursive).py def addNums(numbers): if len(numbers) == 1: return (numbers[0]) else: numbers[0] = numbers[0] + addNums(numbers[1:]) print (numbers[0]) return numbers[0] #ENDSUB marks = [3,6,2,8] total = addNums(marks) print ("Total v1 = ",total) print("\n\nVersion 2, list of 4 numbers 3,6,2,8") #version 2, worksheet 1 question 2 def addNums2(numbers): if len(numbers) > 1: # print ("Before call, numbers[0] =",numbers[0], # "length(numbers) = ",len(numbers)) numbers[0] = numbers[0] + addNums2(numbers[1:]) print (numbers[0]) return numbers[0] #ENDSUB marks = [3,6,2,8] total = addNums2(marks) print ("Total v2 = ",total)