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 The Question Classes & the Plan

How does adding the parameter `Question` extend the Class Add and Class Multiply ?

In the questions.py file, there are three Classes--Question, Add, and Multiply. The Add and Multiply class have a parameter that is itself the class Question. How does python handle this? I don't remember this feature being taught in the previous lessons.

class Question:
   answer = None
   text = None


class Add(Question):
   def __init__(self, num1, num2):
      self.text = '{} + {}'.format(num1, num2) 
      self.answer = num1 + num2


class Multiply(Question):
   def __init__(self, num1, num2):
      self.text = f'{num1} x {num2}'
      self.answer = num1 * num2

3 Answers

Steven Parker
Steven Parker
229,644 Points

Unlike a function, in a class definition one or more terms in parentheses is not a parameter. Instead it is the name of a base class from which this one is derived.

If you're not familiar with inheritance, you might have missed one or more of the beginner courses before moving into the intermediate ones.

Tracy Bowers
Tracy Bowers
6,816 Points

Steven Parker Inheritance was not covered in the basic python track, only basic OOP was covered. So I think this project was probably not in a good part of the sequence for basic python users.

Correct me if I'm wrong, I just watched those OOP modules in the basic python track and I didn't see reference to inheritance.

Steven Parker
Steven Parker
229,644 Points

I know that the track contents have changed since I took it, and if they accidentally removed the instruction regarding class derivation and inheritance, you might want to point it out to the Support staff directly.

Thank you Tracy Bowers I was scratching my head over this one. Good to know I'm not going crazy.

Tracy Bowers
Tracy Bowers
6,816 Points

Ok, so I just found a different OOP module that covers more topics. I've sorta stopped this datetime module just so I can dig more into OOP. I think Ken the instructor alluded to it in his video. It was not really showing up in the python track for some reason.

https://teamtreehouse.com/library/objectoriented-python-2

I could probably continue datetime but my undiagnosed OCD won't let me continue until I understand the way Ken implemented the classes in this app.

Good luck Jason