def command_interface():
print('Therapist\n---------')
print(
'Talk to the program by typing in plain English, using normal upper-')
print('and lower-case letters and punctuation. Enter "quit" when done.')
print('=' * 72)
print('Hello. How are you feeling today?')
s = ''
therapist = Eliza()
while s != 'quit':
try:
s = input('> ')
except EOFError:
s = 'quit'
while s[-1] in '!.':
s = s[:-1]
print(therapist.respond(s))
if __name__ == "__main__":
command_interface()
再正则表达式
Eliza
模块中,发现只要输入quit,程序就可以终止。于是想把此功能加入到对话机器人中,但尝试一番无法加入。以下是思考过程。Eliza
模块中是如何做到的。使用循环只要输入不等于quit,就把值传入respnd方法,匹配正则表达式,并随机替换相应的字符串。Garfield
类中添加判断条件,来终止程序。尝试一番还是不行。老师能否给点思路。