下面是一个简单的实现:

# 定义一个空字典,用于存储单词和其对应的解释
word_dict = {}

# 录入单词和对应的解释
def add_word():
    while True:
        word = input("请输入单词(输入q退出):")
        if word == "q":
            break
        definition = input("请输入解释:")
        word_dict[word] = definition

# 查找单词
def search_word():
    word = input("请输入要查找的单词:")
    if word in word_dict:
        print(f"{word}: {word_dict[word]}")
    else:
        print("未找到该单词")

# 主程序循环
while True:
    choice = input("请选择功能(1-录入单词,2-查找单词,q-退出):")
    if choice == "1":
        add_word()
    elif choice == "2":
        search_word()
    elif choice == "q":
        break
    else:
        print("输入有误,请重新输入")

这段代码首先定义了一个空字典word_dict,用于存储单词和对应的解释。然后定义了两个函数add_wordsearch_word,分别实现录入单词和查找单词的功能。在主程序循环中,根据用户的选择调用不同的函数。

用python实现录入单词表和查找单词的功能

原文地址: https://www.cveoy.top/t/topic/bevb 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录