#!/usr/bin/env python
# -*- coding:utf-8 -*-
#Author: ss
import pickle #泡菜模块
f = open('1.pkl','rb')
answer = pickle.load(f)
print(answer)
f.close() #关闭文件,为了重新打开时指针在开头位置
while True:
question = input("请输入要提问的问题:")
if question == 'get':
if answer:
print('已有问题是:{}'.format(list(answer.keys())))
else:
print('还没有数据!请提问补充问题!')
elif question == 'exit':
print('谢谢使用,再见')
break
elif question == 'del':
while True:
del_question = input('请输入要删除的问题')
if del_question in answer:
del answer[del_question]
elif del_question == 'quit':
break
else:
print('找不到该问题')
else:
for i in list(answer.keys()):
if question in i:
print("答案是:{}".format(answer[i]))
break
else:
huida = input("请你告诉我:")
answer[question] = huida
f = open('1.pkl','wb')
pickle.dump(answer,f)
f.close()