fork download
  1.  
Success #stdin #stdout 0.02s 9176KB
stdin
# 單詞數據庫
words = [
    {"word": "Hello", "translation": "你好", "example": "Hello! How are you?"},
    {"word": "Thank you", "translation": "謝謝", "example": "Thank you for your help."},
    {"word": "Goodbye", "translation": "再見", "example": "Goodbye! See you tomorrow."},
    {"word": "Please", "translation": "請", "example": "Please pass me the salt."},
]

def display_words():
    print("每日單詞列表:")
    for i, word in enumerate(words, start=1):
        print(f"{i}. {word['word']} - {word['translation']}")

def show_word_details(index):
    if 0 <= index < len(words):
        word = words[index]
        print("\n單詞詳情:")
        print(f"單詞:{word['word']}")
        print(f"翻譯:{word['translation']}")
        print(f"例句:{word['example']}\n")
    else:
        print("\n無效的索引,請重試。\n")

def main():
    while True:
        print("\n歡迎使用語言學習程式!")
        print("1. 查看每日單詞")
        print("2. 選擇單詞查看詳情")
        print("3. 離開程式")
        choice = input("請選擇功能 (1/2/3):")
        
        if choice == "1":
            display_words()
        elif choice == "2":
            try:
                word_index = int(input("請輸入單詞編號 (1-4):")) - 1
                show_word_details(word_index)
            except ValueError:
                print("\n請輸入有效的數字。\n")
        elif choice == "3":
            print("感謝使用,再見!")
            break
        else:
            print("\n無效選擇,請重試。\n")

# 運行程式
if __name__ == "__main__":
    main()
stdout
Standard output is empty