Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Recursion
#2
Well, there are two things that could cause errors that I see. One, line 5 needs to be indented or you will get an indentation error. Two, your recursive function has no stop case, so it will recurse forever, and eventually cause a recursion error. For example, take power(3, 2). That will call power(3, 1), which will call power(3, 0), which will call power(3, -1), which will call power(3, -2), and so on. You want to stop and just return n when p == 1.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
Recursion - by leodavinci1990 - Nov-20-2019, 01:29 AM
RE: Recursion - by ichabod801 - Nov-20-2019, 01:42 AM
RE: Recursion - by ThomasL - Nov-20-2019, 06:21 AM
RE: Recursion - by Malt - Nov-20-2019, 08:46 AM
RE: Recursion - by ChislaineWijdeven - Nov-20-2019, 10:25 AM
RE: Recursion - by sumana - Nov-21-2019, 11:03 AM
RE: Recursion - by ThomasL - Nov-27-2019, 01:24 PM
RE: Recursion - by leodavinci1990 - Nov-27-2019, 07:16 AM

Forum Jump:

User Panel Messages

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