這每一個選項是我到目前爲止的代碼:打印上新的生產線
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"]
score = 0
answer_choices = [c.split()[:3] for c in answer_choices]
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, "%")
我的代碼運行,但answer_choices(所以問題的選項),不要每個列表元素的新線顯示。我怎樣才能做到這一點?如果您刪除/註釋行
answer_choices = [c.split()[:3] for c in answer_choices]
,你想你會得到的輸出的解釋也將是不錯
請重新粘貼您的代碼,並使用「{}」按鈕將其縮進。很難說出你的'for'循環裏面應該有什麼。 – luther