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 trial

Python

HELP regarding self.start_time and self.end_time

In the summary function:

def summary(self): print("You got {} out of {} correct!".format(self.total_correct(), len(self.questions))) print("It took you {} seconds to finish the quiz!".format((self.end_time - self.start_time).seconds))

start_time and end_time are function attributes. How can the summary function access these values if they are never declared on the class or instance scope?

A little confused here. Any help would be appreciated!

1 Answer

Steven Parker
Steven Parker
243,656 Points

Actually, self.start_time and self.end_time are instance variables. They are created in "take_quiz" using the "self" context that is passed to it. This makes them available to every method in the class.

Without the "self" prefix, they would have been local to the method as you suggested.

For future questions, remember to provide a link to the relevant course page.