这是一个问答游戏源代码(自己写的)请在python中用)
def ask_question(question, answer):
user_answer = input(question + " ")
if user_answer.lower() == answer.lower():
print("回答正确!\n")
return True
else:
print("回答错误!\n")
return False
def main():
questions = [
{
"question": "1 + 1 = ?",
"answer": "2"
},
{
"question": "首都是哪里?",
"answer": "北京"
},
{
"question": "世界上最高的山是哪座山?",
"answer": "珠穆朗玛峰"
}
]
print("欢迎来到答题游戏!")
score = 0
for q in questions:
question_text = q["question"]
correct_answer = q["answer"]
result = ask_question(question_text, correct_answer)
if result:
score += 1
print(f"游戏结束!您的得分是:{score}/{len(questions)}")
if __name__ == "__main__":
main()