Aug-17-2020, 06:35 PM
If the object is to return the sum of digits from 1 to n, you did not achieve this at all as you do not return a value.
Exit() does not make this work. It just stops the recursion from unwinding.
A recursive function is defined in terms of itself. In this case
Exit() does not make this work. It just stops the recursion from unwinding.
A recursive function is defined in terms of itself. In this case
recsum(n) = recsum(n-1) + n
. Usually there is a special case value that signals the end of recursion such as recsum(1) = 1
. THis should be pretty easy to translate to Python. There will be no while or for loops.