Advertisement
Aqib12

Untitled

Aug 25th, 2020
1,460
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.59 KB | None | 0 0
  1. import random
  2.  
  3. hedges = ("Please tell me more.",
  4.           "Many of my patients tell me the same thing. ",
  5.           "Please continue.")
  6.  
  7. qualifiers = ("Why do you say that? ",
  8.               "You seem to think that ",
  9.               "Can you explain why? ")
  10.  
  11. replcements = {"I": "you", "me": "you", "my": "your",
  12.                "we": "you", "us": "you", "mine": "yours"}
  13.  
  14.  
  15. def reply(sentence):
  16.     """Builds and returns a reply to the sentence."""
  17.     probability = random.randint(1, 4)
  18.     if probability == 1:
  19.         return random.choice(hedges)
  20.     else:
  21.         return random.choice(qualifiers) + changePerson(sentence)
  22.  
  23.  
  24. def changePerson(sentence):
  25.     """Replaces first person pronouns with second person                   pronouns."""
  26.  
  27.     words = sentence.split()
  28.     replyWords = []
  29.     for word in words:
  30.         replyWords.append(replcements.get(word, word))
  31.     return " ".join(replyWords)
  32.  
  33.  
  34. def main():
  35.     """Handles the interaction between patient and doctor."""
  36.     print("Good morning, I hope you are well today.")
  37.     print("What can I do for you?")
  38.     inputs = {}
  39.     while True:
  40.         sentence = input("\n>> ")
  41.         if sentence.lower() in inputs.keys():
  42.             inputs[sentence.lower()] += 1
  43.         else:
  44.             inputs[sentence.lower()] = 1
  45.         if inputs[sentence.lower()] > 2:
  46.             print("Your question is already answered")
  47.         if sentence.upper() == "QUIT":
  48.             print("Have a nice day!")
  49.             break
  50.         print(reply(sentence))
  51.  
  52.  
  53. # The entry point for program execution
  54. if __name__ == "__main__":
  55.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement