用python编写的测试英语单词的程序
时间: 2024-02-21 14:00:26 浏览: 108
Great! Here's a simple program that can help you test your English vocabulary.
```python
import random
# Define a list of words to be tested
words = ['apple', 'banana', 'cherry', 'orange', 'pear', 'grape', 'watermelon', 'pineapple', 'kiwi', 'mango']
# Set the number of questions to be asked
num_questions = 5
# Shuffle the list of words
random.shuffle(words)
# Loop through the shuffled list and ask questions
for i in range(num_questions):
word = words[i]
answer = input(f"What is the meaning of '{word}'? ")
# Check if the answer is correct and print the result
if answer.lower() == 'fruit':
print("Correct!")
else:
print("Incorrect!")
```
In this program, we first define a list of words to be tested. We then set the number of questions to be asked and shuffle the list of words using the `random.shuffle` function.
We then loop through the shuffled list and ask a question for each word using the `input` function. We check if the answer is correct (in this case, the correct answer is 'fruit') and print the result.
You can modify the program to include more words, change the number of questions, and even add more types of questions (e.g. asking for synonyms or antonyms).
阅读全文