Python Forum

Full Version: Please let me understand
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
def clinic():
    print "You've just entered the clinic!"
    print "Do you take the door on the left or the right?"
    answer = raw_input("Type left or right and hit 'Enter'.").lower()
    if answer == "left" or answer == "l":
        print "This is the Verbal Abuse Room, you heap of parrot droppings!"
    elif answer == "right" or answer == "r":
        print "Of course this is the Argument Room, I've told you that already!"
    else:
        print "You didn't pick left or right! Try again."
        clinic()

clinic()
Here I want to understand, why "clinic()" used for two times?
I am a beginner, So please help me to understand...!
So, first to say that this is not good example of code. Same result can be achieved with 'better' code.

on line 13 they call the function clinic. It expect user to make a choice - left or right. If user enter something different they want to ask again. That is why they call clinic again on line 11. Just FYI this approach is called recursion.

Couple of more things - this looks like text adventure game, however one with poor design. They use if/elif/else to control the flow. Look at this tutorial

Second - this is python2 code. As a new to python you should start with python3, not python2. Official support for python 2 will end 1 January 2020.
Thank you so much sir, now I understand why used that code there & I'll sure followup all rules & regulations about posting & asking question. again thank you for your support.
I forgot to link the text adventure game tutorial
https://python-forum.io/Thread-Text-Adve...dictionary