Python Forum

Full Version: Recursive help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
This function returns nothing. Once all recursive calls are performed, the program will return nothing because you have no return statement after line #12. You need to change #12 to return time(attack,calm,worker) to get desired result.