• Uncategorized

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


Warning: Undefined array key 0 in /www/wwwroot/followtutorials.com/wp-content/themes/hueman/single.php on line 9

Warning: Attempt to read property "cat_name" on null in /www/wwwroot/followtutorials.com/wp-content/themes/hueman/single.php on line 9

Warning: Undefined array key 0 in /www/wwwroot/followtutorials.com/wp-content/themes/hueman/single.php on line 14

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

Warning: Undefined array key 0 in /www/wwwroot/followtutorials.com/wp-content/themes/hueman/single.php on line 15

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