Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Recursive help
#1
Hi,
I need a little help understanding python recursive functions. My function stops at an integer instead of returning a bool like I want it to.


def time(attack, calm, worker): #2, 3, 9 goes in
    
    if worker - attack <= 0: #will 9 - 2 = 0 or less? 
        return False
    else:
        worker = worker - attack #Stops here at 2. I know because I printed worker here in the function
    if worker - calm <= 0: # 2 - 3 would be negative 1, so it should return true right?
        return True
    else:
        worker = worker - calm
    
    time(attack, calm, worker) # recursive calls
9 would become 7, then 4, then 2, then trying to subtract 3 would make it return a boolean.
At least, that's my intent. I don't understand what I'm doing wrong.
Reply


Messages In This Thread
Recursive help - by jjordan33 - Jul-20-2019, 04:28 AM
RE: Recursive help - by scidam - Jul-20-2019, 07:11 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Combine Two Recursive Functions To Create One Recursive Selection Sort Function Jeremy7 12 7,503 Jan-17-2021, 03:02 AM
Last Post: Jeremy7

Forum Jump:

User Panel Messages

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