首先,新建一个文本文件做准备:
订单|如果您有任何订单问题,可以登录淘宝账号,点击“我的订单”,查看订单详情。
物流|如果您有任何订单问题,可以登录淘宝账号,点击“我的订单”,查看商品物流。
账户|如果您有任何订单问题,可以联系淘宝客服,电话:xxxx-xxxxxxxx
支付|如果您有任何支付问题,可以联系支付宝客服,QQ:xxxxx
代码:
def find_answer(question):
with open("reply.txt", "r", encoding='UTF-8') as file:
while 1:
line = file.readline()
if not line:
break
keyword = line.split("|")[0]
reply = line.split("|")[1]
if keyword in question:
return reply
return False
if __name__ == '__main__':
question = input("Hi,您好,小蜜在此等主人很久了,有什么烦恼快和小蜜说吧!")
while 1:
if question == "BYE":
break
reply = find_answer(question)
if not reply:
question = input("小蜜不知道你在说什么,您可以问一些关于订单、物流、账户、支付等问题,(退出请输入BYE)")
else:
print(reply)
question = input("小主,你还可以继续问一些关于订单、物流、账户、支付等问题(退出请输入BYE)")
print("小主再见!")