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 Dates and Times in Python (2014) Let's Build a Timed Quiz App Taking The Quiz

Brian Anstett
Brian Anstett
5,831 Points

How can Summary() access start_time and end_time?

The two values start_time and end_time are created and assigned a value in the take_quiz() method, but are then used again in the summary() method. Start_time and end_time are not public variables and were not declared at a class level. How can summary() use these variables without passing those variables as parameters to the summary() method

1 Answer

Alx Ki
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Alx Ki
Python Web Development Techdegree Graduate 14,822 Points

take_quiz() calls self.summary() in it's return. That's how take_quiz() gives self.summary() it's variables. That's the magic of self. which makes variables belong to whole class and it's functions.

Try this:

class Showhow:

    def function(self):
        self.number = 1
        self.anothernumber = 2
        return self.plus()

    def plus(self):
        print(self.number + self.anothernumber)

Showhow().function()