一个英文单词包含单词与 词的注释,结构如下:
Words =[{" word ":" about "," note ":"在附近,关于"),(" word ":" post "," note ":"邮寄、投递"}]
所有的单词组成一个列表,每个单词与注释成为一个字典,程序的功能就是管理这样一组单词记录,程序有查找单词、增加单词、更新注释、删除单词、显示单词等功能
# 定义单词列表
words = [{"word": "about", "note": "在附近,关于"},
{"word": "post", "note": "邮寄、投递"}]
# 查找单词函数
def search_word():
word = input("请输入要查找的单词:") # 遍历单词列表,查找相应单词
for w in words:
if w["word"] == word:
print(f"{word}: {w['note']}")
return
print("该单词不在记录中")
# 增加单词函数
def add_word():
word = input("请输入要添加的单词:") # 判断该单词是否已经在记录中,避免重复添加
for w in words:
if w["word"] == word:
print("该单词已经在记录中")
return
note = input("请输入单词注释:") # 将新单词加入单词列表
words.append({"word": word, "note": note})
print(f"单词{word}已添加")
# 更新注释函数
def update_note():
word = input("请输入要更新注释的单词:") # 遍历单词列表,查找相应单词并更新注释
for w in words:
if w["word"] == word:
n