-
-
Save xatier/4dbeddd926e0567dc8df16c1c5d9b0bf to your computer and use it in GitHub Desktop.
Yet another chatbot
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
#!/usr/bin/env python3 | |
import itertools | |
whats = [ | |
'自經區', '自貿區', | |
'摩天輪', '愛情摩天輪', '愛情產業鏈', | |
'發大財', | |
'迪士尼', | |
'F1', 'F1賽車場', 'F1 賽車場', | |
'賭馬', '賽馬', | |
'九二共識', '一中各表', '一國兩制', '兩岸統一', | |
] | |
known_questions = {} | |
for what in whats: | |
type_a = itertools.product(['什麼是', ''], [what], ['', '?', '?']) | |
for _ in type_a: | |
known_questions[''.join(_)] = what | |
type_b = itertools.product([what], ['是什麼'], ['', '?', '?']) | |
for _ in type_b: | |
known_questions[''.join(_)] = what | |
def ask_me(): | |
question = input('議員請發問:') | |
if question in known_questions: | |
answer = known_questions[question] | |
print(f'總目標是高雄要發大財,這個{answer}只是其中一部份,好不好?謝謝。') | |
else: | |
print('你說的不是重點,重點是高雄要發大財。') | |
print() | |
def main(): | |
while True: | |
try: | |
ask_me() | |
except KeyboardInterrupt: | |
break | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment