Ask Question

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. 21 August, 14:44
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers