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 trialPatrick Lannan
4,792 PointsUnderstanding question_start/end
I was playing around with deconstructing the quiz we set up in the lesson and got rid of the question_start and question_end in my ask method. It seemed like it wouldn't effect anything since I wasn't keeping track of how long it took to complete each individual question, and that was the only difference in my code from the version that just worked. When I ran my code, it displayed the quiz and I was able to input all of the answers. But once it came time to be given my summary, the code crashed because it said if answer[0]: "'bool' object is not subscript able," referring to the total_correct method. What does that mean and why would that happen by removing the question_start/end and keeping everything else the same.
2 Answers
Steven Parker
231,236 PointsIt sounds like you were expecting "answer" to be an array, but at some point in the code it was assigned with a true/false value instead.
If you'd like help finding the specific cause, show your code here. Even better, make a snapshot of your workspace and post the link to it here.
UPDATE: After seeing the snapshot, the "ask" method originally returns a tuple containing the result (a Bool) and the time taken. If you just removed the time taken from the "return" then taking the quiz would fill "answers" with Bool values instead of tuples. So later in "total_correct", when the loop tries to select the result part of what it expects to be a tuple by applying a subscript ("answer[0]
"), you get the error "'bool' object is not subscriptable,"
So to completely remove the timing, you need to change every place where "answers" is accessed to treat it as a list of results instead of a list of tuples (with results and times).
Or a quick fix would be to just make sure "ask" still returns a tuple even if you don't care about the time:
return correct, None # return a tuple but with no time
Patrick Lannan
4,792 Pointshttps://w.trhou.se/acujrookp2 Here's a snapshot. This should work fine, but once I remove the question_start and question_end from the ask method, the quiz finishes with the bool value not subscriptable error. All this is in the quiz.py by the way