Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialsonny unverferth
Python Web Development Techdegree Student 2,889 Pointsdatetime in quiz.py
Hello! Can someone smarter than me explain why we must output "question_start - question_end" in the ask() method ? I feel dumb. Where else does the script use it? I see it as the second item in the tuples in the "Quiz().answers" list. It seems redundant to have it since the "take_quiz()" method is keeping time with "start_time " and "end_time".
1 Answer
Kazuma Namioka
20,674 PointsIt's not a question of smart or not, you're right that it isn't really put to use here. Ken mentioned he would log the time it takes to answer each individual question, but that he would leave it up to keen students to then do something with that information, like display it for the quiz-taker at the summary stage.
Still, it does mean the ask() method returns a tuple, so in this method:
def total_correct(self):
# return the total # of correct answers
total = 0
for answer in self.answers:
if answer[0]:
total += 1
return total
it is necessary to specify answer[0] because the value at index 0 is the value that says whether the answer is True or False, while the second value at answer[1] is the time it took for the quiz-taker to provide said answer.