Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Please let me understand
#1
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...!
Reply
#2
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.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
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.
Reply
#4
I forgot to link the text adventure game tutorial
https://python-forum.io/Thread-Text-Adve...dictionary
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020