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 trialArtur Ferfecki
5,950 PointsStuck on the incrementation of laps when run_lap method is called. No idea how to proceed further.
I tried the code until the point when I create the run_lap method and it works. I have trouble to proceed further with the laps attribute I just have no clue from which end to grab it
class RaceCar:
laps = 0
def __init__(self, color, fuel_remaining, **kwargs):
self.color = color
self.fuel_remaining = fuel_remaining
for attribute, value in kwargs.items():
setattr (self, attribute, value)
def run_lap (self, length):
return self.fuel_remaining - length*0.125
2 Answers
Clayton Perszyk
Treehouse Moderator 48,850 PointsHey Artur,
You don't need to return anything from run_lap , but you will need to reassign the updated value back to self.fuel_remaining. Also, laps should be an instance variable; currently it is a Class variable, and as such will apply to all instances of the Class. Other than that, looks good!
Artur Ferfecki
5,950 PointsThanks Clayton, I adjusted my code and it works now.
To clarify what do you mean by "Also, laps should be an instance variable; currently it is a Class variable, and as such will apply to all instances of the Class."? How does laps apply to all instances and what is the difference if I include laps to class (as it is in the piece of code above) or I put laps under init?