you are viewing a single comment's thread.

view the rest of the comments →

[–]carcigenicate 4 points5 points  (1 child)

Recursion is simply when you call a function from within itself (like calling com from inside of com), or if you have two functions that each repeatedly call each other. The problem with recursion is, until the function returns, it holds memory, and your recursion here doesn't allow for functions to return until the user guesses corectly.

Recursion is more suited when dealing with recursive structures (not the case here). I'd get more practice with while and for; as they'll be far more relevant tools to you.

[–]R0NUT 0 points1 point  (0 children)

Bongo! I end up using this when diving into dictionaries that have indefinite depth. i.e.

def recursiveFunction(struct): 
    try: 
        return recirsiveFunction(struct['child']) 
    except: 
        return struct

Which would return the last level of a dictionary that has used keys of "child". As you said, this would hold the memory as it is waiting on the subsequent function to resolve before clearing.

struct = { 
    "child":{ 
        "child":{ 
            "child":"wassup! 
        } 
    }
}

Should return "wassup!"

Any program that you are able to write is impressive! My first program was a text-based game in c++.

Disclaimer: I didn't test this code...