python答题系统代码
时间: 2023-08-29 10:12:19 浏览: 106
以下是一个简单的 Python 答题系统代码示例,可以根据需要进行修改:
```python
questions = {
"What is the capital of France?": "Paris",
"What is the largest country in the world by land area?": "Russia",
"Who invented the telephone?": "Alexander Graham Bell",
"What year did World War II end?": "1945",
"What is the chemical symbol for gold?": "Au"
}
score = 0
for question, answer in questions.items():
print(question)
user_answer = input("Your answer: ")
if user_answer.lower() == answer.lower():
print("Correct!")
score += 1
else:
print("Incorrect.")
print("You scored", score, "out of", len(questions), "questions.")
```
这个代码使用字典存储问题和答案。它遍历字典,对于每个问题,询问用户并检查他们的回答是否正确。最后,程序会输出用户的得分。
阅读全文