Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
OOP - method and variable Declaration issue - Assistance Required.
I am not understanding my error, and what I am doing wrong in this exercise.
I have been requested to make sure that the 'laps' attribute is referenced in the init method. I therefore removed the 'laps' attribute for the RaceCar class.
I am getting Error message that do not explain where I am going wrong. Kindly assist.
class RaceCar: def __init__(self, color, fuel_remaining, laps, **kwargs): self.color = color self.fuel_remaining = fuel_remaining self.laps = laps for key, value in kwargs.items(): setattr(self, key, value) def run_lap(self, length): self.fuel_remaining -= (length * 0.125) self.laps += 1
Jennifer NordellTreehouse Teacher
Hi there, Emmanuel Ade! You're doing fantastic and you're right at the end of this task. The problem here, is that they want laps to be set to 0 by default. This means that when creating a new
RaceCar instance, they must send in the color and the fuel_remaining, but they shouldn't necessarily have to specify the laps. They could, but it wouldn't be required. We can do this by assigning laps a default value in the
def __init__(self, color, fuel_remaining, laps=0, **kwargs):
That tells Python that if we don't send in anything for
laps, to go ahead and assign a value of 0 to laps. Which makes sense, in my opinion. If we just built a brand new race car and it's coming off the assembly line, then it's never run any laps before
Hope this helps!