Ask Question
18 December, 00:56

Implement the sum_positive_numbers function, as a recursive function that returns the sum of all positive numbers between the number n received and 1. For example, when n is 3 it should return 1+2+3=6, and when n is 5 it should return 1+2+3+4+5=15.

+5
Answers (1)
  1. 18 December, 02:07
    0
    def sum_positive_numbers (n):

    if (n==0 or n==1) : #if n is 0 or 1 return n as its sum also will be n

    return n

    return n+sum_positive_numbers (n-1) #else return n and sum of all the number smaller then n

    print (sum_positive_numbers (3)) # Should be 6

    print (sum_positive_numbers (5)) # Should be 15
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Implement the sum_positive_numbers function, as a recursive function that returns the sum of all positive numbers between the number n ...” 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