# 英语单词记忆系统
word_list = []

def add_word():
    """添加新单词"""
    word = input("Enter a new word: ").strip().lower()
    meaning = input("Enter its meaning: ").strip()
    word_list.append({"word": word, "meaning": meaning})
    print(f"Added: {word} - {meaning}")

def test_memory():
    """测试单词记忆"""
    if not word_list:
        print("No words in your list!")
        return
    
    import random
    test_word = random.choice(word_list)
    
    print(f"What is the meaning of: {test_word['word']}?")
    answer = input("Your answer: ").strip()
    
    if answer.lower() == test_word['meaning'].lower():
        print("✅ Correct!")
    else:
        print(f"❌ Incorrect! The correct meaning is: {test_word['meaning']}")

def view_words():
    """查看所有单词"""
    if not word_list:
        print("Your word list is empty.")
    else:
        print("\nYour Word List:")
        for i, item in enumerate(word_list, 1):
            print(f"{i}. {item['word']} - {item['meaning']}")

# 主菜单
while True:
    print("\n===== English Word Memorizer =====")
    print("1. Add a new word")
    print("2. Test your memory")
    print("3. View all words")
    print("4. Exit")
    
    choice = input("Choose an option (1-4): ")
    
    if choice == '1':
        add_word()
    elif choice == '2':
        test_memory()
    elif choice == '3':
        view_words()
    elif choice == '4':
        print("Goodbye!")
        break
    else:
        print("Invalid choice. Please enter 1-4.")

功能说明

  1. 添加单词:输入单词及其释义,存储在列表中
  2. 记忆测试:随机抽取单词测试记忆,即时反馈正误
  3. 查看词库:显示所有已存储的单词和释义
  4. 退出系统:结束程序运行

使用示例

===== English Word Memorizer =====
1. Add a new word
2. Test your memory
3. View all words
4. Exit
Choose an option (1-4): 1
Enter a new word: algorithm
Enter its meaning: set of rules
Added: algorithm - set of rules

===== English Word Memorizer =====
1. Add a new word
2. Test your memory
3. View all words
4. Exit
Choose an option (1-4): 2
What is the meaning of: algorithm?
Your answer: step-by-step procedure
❌ Incorrect! The correct meaning is: set of rules

这个系统使用基础数据结构实现,可通过添加文件存储功能(如pickle模块)实现数据持久化。

更多推荐