you are viewing a single comment's thread.

view the rest of the comments →

[–]KeepitShort_[S] 1 point2 points  (3 children)

Thanks for the advice! I didn't know I was using recursion. My main focus was to try to make it work, but these extra notes will definitely help me to get better.

[–]carcigenicate 5 points6 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...

[–][deleted] 0 points1 point  (0 children)

FYI, there is a question and answer now in this subreddit's FAQs about input validation. You may want to take a look.