标签:输入提示 pytho raw 好的 str 指令 val sorted inpu
dict = {
‘hello‘: ‘hello‘
}
flag = ‘c‘
work = True
print ‘hi,my name is python.‘
print ‘do you want chat with me?‘
while flag == ‘c‘ or ‘t‘:
flag = raw_input("你可以选择和我聊天(c)和我训练对话(t),或者让我离开(l)?(c/t/l)")
if flag == "t":
question = raw_input("请输入问题(key): ")
answer = raw_input("请输入你的答案(value):")
dict[str(question)] = str(answer)
print u"训练成功"
print u"现在我已经会%d个问题了!" % len(dict)
continue
elif flag == ‘c‘:
if len(dict) == 0:
print u"我现在还不会问题,请先训练我!"
continue
chat_word = raw_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 u"抱歉,这句话我还不会回答"
work = True
elif flag == ‘l‘:
print u‘好的,下次再见‘
break
else:
print u‘请输入提示的指令‘
continue
标签:输入提示 pytho raw 好的 str 指令 val sorted inpu
原文地址:https://www.cnblogs.com/kzkzkz/p/10328082.html