I'm going through "Learn Python the Hard Way" by Zed Shaw.
I'm currently on lesson 36: http://learnpythonthehardway.org/book/ex36.html
My issue:
I'm trying to create my own game based on what Zed did in lesson 35: http://learnpythonthehardway.org/book/ex35.html
In his game he creates the following function to terminate the game:
def dead(why):
print why, "Good job!"
exit(0)
That's used in if/else statements such as this:
choice = raw_input("> ")
if choice == "left":
bear_room()
elif choice == "right":
cthulhu_room()
else:
dead("You stumble around the room until you starve.")
When I run his program it exits when calling the dead function.
However, when I try and use this same construct in my own code I get the following error:
RunTime Error: Maximum Recursion Depth Exceeded
after lines of code spitting out the spot in my program where the exit(0) function is called.
Here's an example of how I have used it in my program:
def exit(message):
print message, "Your adventure is over."
exit(0)
With if/else statements like this:
answer = raw_input("> ")
if "stay" in answer:
exit("Adventure and excitement are only available to those who participate.")
elif "don't" in answer:
exit("Great things were never achieved by cowards. Please rethink your choice.")
elif "wait" in answer:
exit("Great things were never achieved by cowards. Please rethink your choice.")
elif "outside" in answer:
exit("Adventure and excitement are only available to those who participate.")
elif "enter" in answer:
lobby()
elif "go" in answer:
lobby()
elif "through" in answer:
lobby()
elif "inside" in answer:
lobby()
else:
exit("Well, you're no fun!")
It's not clear to me why it works in Zed's program but doesn't in my own. (And yes, I know that's probably an egregious use of elif's but my programming chops prohibit me from doing much else right now).
At first I thought it was due to how I was using while loops in my program but I've deleted all those and I'm having the same issues.
Thank you.