Q:

Write a python program to create a recursive function to calculate the sum of numbers from 0 to 10.

belongs to collection: Python Functions Exercises

0

Create a recursive function

Write a program to create a recursive function to calculate the sum of numbers from 0 to 10.

A recursive function is a function that calls itself, again and again.

Expected Output:

55

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Solution:

def addition(num):
    if num:
        # call same function by reducing number by 1
        return num + addition(num - 1)
    else:
        return 0

res = addition(10)
print(res)

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Assign a different name to function and call it th... >>
<< Create an inner function to calculate the addition...