Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
function fails to exit
#5
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 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.
Reply


Messages In This Thread
function fails to exit - by harig3 - Aug-16-2020, 07:47 PM
RE: function fails to exit - by BitPythoner - Aug-16-2020, 08:21 PM
RE: function fails to exit - by harig3 - Aug-17-2020, 05:48 PM
RE: function fails to exit - by deanhystad - Aug-16-2020, 08:51 PM
RE: function fails to exit - by deanhystad - Aug-17-2020, 06:35 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  python difference between sys.exit and exit() mg24 1 1,853 Nov-12-2022, 01:37 PM
Last Post: deanhystad
  Exit function from nested function based on user input Turtle 5 2,931 Oct-10-2021, 12:55 AM
Last Post: Turtle
  Exit Function - loop Tetsuo30 2 2,066 Sep-17-2020, 09:58 AM
Last Post: Tetsuo30

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020