Created
July 31, 2020 13:32
-
-
Save kshirsagarsiddharth/1e31c21bfa7999b3cae79e83069726ed to your computer and use it in GitHub Desktop.
compilation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import random | |
| def bad_service_chatbot(): | |
| answers = ["We don't do that", | |
| "We will get back to you right away", | |
| "Your call is very important to us", | |
| "Sorry, my manager is unavailable"] | |
| yield "Can I help you?" | |
| s = "" | |
| while True: | |
| if s is None: | |
| break | |
| s = yield random.choice(answers) | |
| def pig_latin_sentence(sent): | |
| output = [] | |
| for word in sent.split(): | |
| if word[0] in "aeiou": | |
| output.append(word + "ay") | |
| else: | |
| output.append(word[1:] + word[0] + "ay") | |
| return " ".join(output) | |
| def pl_translate(): | |
| sentence = "" | |
| while True: | |
| sentence = yield pig_latin_sentence(sentence) | |
| if sentence is None: | |
| break | |
| def switchbord(): | |
| while True: | |
| choice = yield "send 1 for pig latin, 2 for support" | |
| if choice == 1: | |
| yield from pl_translate() | |
| elif choice == 2: | |
| yield from bad_service_chatbot() | |
| elif choice == 3: | |
| return | |
| else: | |
| print("Bad choice") | |
| s = switchbord() | |
| print(next(s)) | |
| print(s.send(1)) | |
| print(s.send("hello world")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment