机器人

dict = {
        'Hello'                             :'Hello',
        'Nice to meet you'                  :'Nice to meet you too',
        'Which fruit do you like best'      :'I like yaoxu very much',
        'How old are you'                   :'20 year old',
        'You are handsome'                 :'Thank you',
        }

flag = 'c'
work = True

print ('Hi,my name is Yaoxu.')
print ('Do you want chat with me?')
while flag == 'c' or 't':
    flag = input("你可以选择和我聊天(c)还是训练我对话(t),或者让我离开(l)?(c/t/l)  ")

    if flag == "t":
        question = input("请输入问题(key): ")
        answer = input("请输入回答(value): ")
        dict[str(question)] = str(answer)
        print ("训练成功")
        print ("现在我已经会%d个问题了!" % len(dict))
        continue

    elif flag == 'c':
        if len(dict) == 0:
            print ("现在我还不会任何问题,请先训练我!")
            continue;

        chat_word = input("谢谢你跟我聊天,你想对我说点什么? : ")

        for key in sorted(dict.keys()):
            if str(chat_word) == key:
                work = True
                print ("",dict[key])
                break
            else:
                work = False

            if work == False:
                print ("抱歉,这句话我还不会回答")
                work = True

            elif flag == 'l':
                print ("好的,下次再见")
                break

            else:
                 print ("请输入提示的指令")
                 continue
                

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值