Last active
May 10, 2019 06:18
-
-
Save fkztw/631b10a0331613589e2fae86a2b9ddcf to your computer and use it in GitHub Desktop.
Yet another chatbot
This file contains 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("總目標是高雄要發大財,這個{}只是其中一部份,好不好?謝謝。".format(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