Python Program for Calculating the Sum of a List of Numbers using recursion

In this example, we will write a recursive function to convert decimal to binary. To better understand this example, make sure you have knowledge of the following tutorials:-

Loading...

Python Program for Calculating the Sum of a List of Numbers using recursion

def listsum(numList):
    if len(numList) == 1:
        return numList[0]
    else:
        return numList[0] + listsum(numList[1:])

print(listsum([1, 2, 3, 5, 7, 9]))

The output of the above program is:-

27

Loading...
SHARE Python Program for Calculating the Sum of a List of Numbers using recursion

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

Share