Ask Question
14 December, 17:25

The sum of the numbers 1 to n can be calculated recursively as follows: The sum from 1 to 1 is 1. The sum from 1 to n is n more than the sum from 1 to n-1 Write a function named sum that accepts a variable containing an integer value as its parameter and returns the sum of the numbers from 1 to to the parameter (calculated recursively).

+4
Answers (1)
  1. 14 December, 18:51
    0
    See explaination

    Explanation:

    The code

    #function named sum that accepts a variable

    #containing an integer value as its parameter

    #returns the sum of the numbers from 1 to to the parameter

    def sum (n):

    if n = = 0:

    return 0

    else:

    #call the function recursively

    return n + sum (n - 1)

    #Test to find the sum ()

    #function with parameter 5.

    print (sum (5))
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “The sum of the numbers 1 to n can be calculated recursively as follows: The sum from 1 to 1 is 1. The sum from 1 to n is n more than the ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers