我正在寫這個python代碼,它將允許用戶選擇一個簡單和困難的模式,並有多種選擇。每種模式的問題都是一樣的,但硬版本在每個問題中都有更多的選項可供選擇。這是到目前爲止我的代碼:在測驗蟒蛇上製作一個簡單而困難的模式
questions = ["What is 1 + 1",
"What is Batman's real name"]
answer_choices = ["1)1\n2)2\n3)3\n4)4\n5)5\n:",
"1)Peter Parker\n2)Tony Stark\n3)Bruce Wayne\n4)Thomas Wayne\n5)Clark Kent\n:"]
correct_choices = ["2",
"3",]
answers = ["1 + 1 is 2",
"Bruce Wayne is Batman"]
def quiz():
score = 0
for question, choices, correct_choice, answer in zip(questions,answer_choices, correct_choices, answers):
print(question)
user_answer = str(input(choices))
if user_answer in correct_choice:
print("Correct")
score += 1
else:
print("Incorrect", answer)
print(score, "out of", len(questions), "that is", float(score /len(questions)) * 100, "%")
quiz()
我將如何添加簡單的和困難多而不進行新的列表,並具有複製和粘貼的一切嗎?解釋也很好。 預先感謝任何答覆
您需要編寫基於簡單模式列表和其他附加信息(附加選項)生成硬模式列表的代碼。做到這一點的最佳方式大多是意見。 –
你需要查看字典。 – Chris
你應該考慮將'布魯斯·韋恩是蝙蝠俠'改寫爲'蝙蝠俠是布魯斯·韋恩'給出瞭如何提出的問題:) –