0
我的question.info()
方法不記得請求question.ask()
方法中的任何內容。我的方法不記得其他方法的東西
我認爲這是因爲它從初始函數刷新,但是當我刪除初始函數中第一次定義變量的位置時,它會返回一個很大的錯誤。
這是我的代碼:
import time
class question:
def __init__(self, question, answer):
self.question = question
self.answer = answer
self.time = 0
self.attempt = 0
self.correct = False
def ask(self):
start = time.clock()
self.attempt = input(self.question)
self.time = time.clock() - start
if self.attempt == str(self.answer):
self.correct = True
def info(self):
print("Question:", self.question)
print("Answer:", self.answer)
print("Attempt:", self.attempt)
print("Correct:", self.correct)
print("time taken:", self.time)
class test:
def __init__(self, qList):
self.qList = qList
def doTest(self):
for i in range(0, len(self.qList)):
question(self.qList[i][0],self.qList[i][1]).ask()
question(self.qList[i][0],self.qList[i][1]).info()
basicMath = [
["what is 1",1],
["what is 2",2],
["what is 3",3],
["what is 4",4],
["what is 5",5],
]
task = test(basicMath)
task.doTest()