Ask Question
4 October, 12:46

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.

+1
Answers (1)
  1. 4 October, 15:12
    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?
Get 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 & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers