The following are links to additional questions that our community has asked about this exercise:
This list will contain other frequently asked questions that aren’t quite as popular as the ones above.
Currently there have not been enough questions asked and answered about this exercise to populate this FAQ section.
This FAQ is built and maintained by you, the Codecademy community – help yourself and other learners like you by contributing!
Not seeing your question? It may still have been asked before – try searching for it by clicking the spyglass icon () in the top-right of this page. Still can’t find it? Ask it below by hitting the reply button below this post ().
In most other languages, calling a function from within itself is considered bad form unless there is something to control the depth of recursion. How is Python different? It seems odd not to teach defensive programming from the offset unless Python has some magic way of dealing with it?
The first line of defense against runaway recursion is stack overflow. Python has built in exceptions to handle this case. RecursionOverflowError among them.
Under normal circumstances we would be including a base case to detect when the recursion should cease and the call stack wound down to the final return.
It is to be expected that at some point in the study of iteration we will encounter recursion in a comparative sense. The majority of recursion cases can be done with ordinary loops in considerably less operations and time but we are sure to find certain cases where recursion is the best suited implementation. Don’t ask me to give any examples. Doubtless the lines being drawn to our display are an infinite loop of some sort. That might be one.
After clicking Run, the button spins like it’s in an infinite loop.
After waiting a while, this is the output:
You’ve just entered the clinic!
Do you take the door on the left or the right?
Type left or right and hit ‘Enter’.Traceback (most recent call last):
File “python”, line 13, in
File “python”, line 4, in clinic
ExecTimeoutException: Program took too long to terminate.
I learned from another thread that you have to actually click on the console itself and then type right and hit enter or left and hit enter.
I had to click on my console several times after hitting “Run” , click the “cursor” area, and then tried to type and it failed first time. Second time, I hit “Run”, then clicked on the console, typed “Right” and got the correct response/answer. I also ran it again for “left” and that worked as well.
Hope this helps you and others who are starting with Python like me!
p.s : I should also mention you will not see the result of you typing out right, left or anything else in the console. You just have to type it out and press enter and hope it works