Loading [MathJax]/extensions/TeX/AMSsymbols.js

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:-

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

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.


Warning: Undefined variable $category in /www/wwwroot/followtutorials.com/wp-content/themes/hueman/sidebar_tutorial.php on line 10

Warning: Trying to access array offset on null in /www/wwwroot/followtutorials.com/wp-content/themes/hueman/sidebar_tutorial.php on line 10

Warning: Attempt to read property "category_parent" on null in /www/wwwroot/followtutorials.com/wp-content/themes/hueman/sidebar_tutorial.php on line 10
Share