添加功能:
查询功能:
删除功能:
修改功能:
写入文件函数:
程序:
words = {}
def mainpage():
print("*******字典学习系统*******\n"
"1 添加\n"
"2 查询\n"
"3 删除\n"
"4 修改\n"
"5 退出\n"
"************************")
def add():
english = input("请输入英文单词: ")
if english in words:
print("该单词已添加到字典库!")
else:
chinese = input("请输入中文释义: ")
words[english] = chinese
def select():
english = input("请输入你要查询的英文单词:")
if english not in words:
print("字典库中未找到这个单词!")
else:
print("{}:{}".format(english, words[english]))
def delete():
del_english = input("请输入要删除的英文单词:")
if del_english in words:
del words[del_english]
print("删除成功")
else:
print("要删除的单词不存在")
def chance():
change_english = input("请输入要修改中文释义的英文单词:")
if change_english in words:
change_chinese = input("请输入修改后的中文释义:")
words[change_english] = change_chinese
print("修改成功")
else:
print("要修改的单词不存在")
def write():
with open("dict.csv", "w") as w:
for key in words:
english = key
chinese = words[key]
w.write(english + "-" + chinese + '\n')
while True:
mainpage()
option = int(input("请输入所需要功能对应的数字:"))
if option == 1:
add()
write()
elif option == 2:
select()
elif option == 3:
delete()
write()
elif option == 4:
chance()
write()
elif option == 5:
print("已退出系统")
break
else:
print("数字输入有误,无对应功能,请重新输入正确的数字")