一個簡易會學習的問答機器人
阿新 • • 發佈:2018-11-21
dict = {
'hello' :'hello',
'nice to meet you' : 'my pleasure',
'favorite fruit?' : 'peach',
'how old' :'20 years old',
'you are cute' :'thanks'
}
flag = 'c'
work = True
print 'hi i am p'
print 'do you want to chat'
while flag == 'c' or 't':
flag =raw_input('talk(c)or train me(t),or leave(l)')
if flag == 't':
question = raw_input('input question (key):')
answer = raw_input('input answer(value):')
dict[str(question)] = str(answer)
print 'amazing'
print 'i have learned %d questions!'%len(dict)
continue
elif flag == 'c':
if len(dict) == 0;
print 'i feel blank,train me'
continue;
chat_word = raw_input('what do you want to say')
for key in sorted(dict.key()):
if str(chat_word) == key:
work = True
print dict[key]
break
else:
work = False
if work == False:
print 'sorry,no answer'
work = True
elif flag == 'l':
print 'ok byebye'
break
else:
print 'please input'
continue
'hello' :'hello',
'nice to meet you' : 'my pleasure',
'favorite fruit?' : 'peach',
'how old' :'20 years old',
'you are cute' :'thanks'
}
flag = 'c'
work = True
print 'hi i am p'
print 'do you want to chat'
while flag == 'c' or 't':
flag =raw_input('talk(c)or train me(t),or leave(l)')
if flag == 't':
question = raw_input('input question (key):')
answer = raw_input('input answer(value):')
dict[str(question)] = str(answer)
print 'amazing'
print 'i have learned %d questions!'%len(dict)
continue
elif flag == 'c':
if len(dict) == 0;
print 'i feel blank,train me'
continue;
chat_word = raw_input('what do you want to say')
for key in sorted(dict.key()):
if str(chat_word) == key:
work = True
print dict[key]
break
else:
work = False
if work == False:
print 'sorry,no answer'
work = True
elif flag == 'l':
print 'ok byebye'
break
else:
print 'please input'
continue