A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

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

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

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)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now