Challenge: Sum of Lists

Test yourself and implement what you have learned so far in this chapter.

Problem statement

In this challenge, you need to create a recursive function, sum, which returns the total sum of the integers in a List.

Input

The input of the function is a list of integers, numberList, and the index of the last item in numberList.

Output

The output will be the sum of all the integer in numberList.

Sample input

sum([1,2,3,4,5], 4)

Sample output

15

Test yourself

Write your code in the given area. Try the exercise by yourself first, but if you get stuck, the solution has been provided. Good luck!

Create a free account to access the full course.

Continue your learning journey with a 14-day free trial.

By signing up, you agree to Educative's Terms of Service and Privacy Policy