簡單的問題,但不能解決我的生活。我在問瑣事問題,但我想跟蹤正確的答案,所以我做一個計數器。如果不將它重置爲0或獲取過早的參考錯誤,就無法確定放置的位置。在課堂上設置計數器的問題
class Questions():
def __init__(self, question, answer, options):
self.playermod = player1()
self.question = question
self.answer = answer
self.options = options
self.count = 0
def ask(self):
print(self.question + "?")
for n, option in enumerate(self.options):
print("%d) %s" % (n + 1, option))
response = int(input())
if response == self.answer:
print("Correct")
self.count+=1
else:
print("Wrong")
questions = [
Questions("Forest is to tree as tree is to", 2, ["Plant", "Leaf", "Branch", "Mangrove"]),
Questions('''At a conference, 12 members shook hands with each other before &
after the meeting. How many total number of hand shakes occurred''', 2, ["100", "132", "145", "144","121"]),
]
random.shuffle(questions) # randomizes the order of the questions
for question in questions:
question.ask()
拋開你的代碼,並拿出你可以產生相同類型的錯誤的最小的例子。給出預期的行爲和實際行爲,並描述爲什麼你不能理解這種差異。瞭解如何創建[mcve]。 –
會做配偶。讚賞。 –
每場比賽只有一名球員,還是多名球員?如果有多個玩家,「計數」與每個玩家相關聯,而不是與問題有關。順便說一句,'.ask'中'for'循環的縮進被打破了。 –