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 trialSarah Burgart
5,159 Pointswhat am I missing in writing the method for class RaceCar? I suspect it is something in how I am using the attributes
\\ laps = 0
def run_lap(self, length):
self.length = length
self.fuel_remaining -= (self.length * .125)
laps += 1
\\
I am not getting any feedback other than "bummer"
class RaceCar:
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)
laps = 0
def run_lap(self, length):
self.length = length
self.fuel_remaining -= (self.length * .125)
laps += 1
3 Answers
Steven Parker
231,269 PointsUnfortunately, the error messages don't always come with hints. But you're really close!
It looks like you just forgot the "self.
" prefix where you increment "laps
".
Sarah Burgart
5,159 Pointslike this? laps = 0
def run_lap(self, length):
self.length = length
x = (self.length * .125)
self.fuel_remaining -= x
self.laps += 1
b/c that does not work either :/
Steven Parker
231,269 PointsIf I paste your original "racecar.py" code from above directly into the challenge, and then just add "self.
" to the last line, it passes task 2.
Sarah Burgart
5,159 Pointsawesome! thanks - got it that time - all the things need prefix - got it!
Sarah Burgart
5,159 PointsSarah Burgart
5,159 Pointsthe challenge says "Oh, and add a laps attribute to the class, set to 0, and increment it each time the run_lap method is called." - which I took to interpret as wanting a count of any time that method is called, not just per instance. (also I tried it as a self.attribute and that didn't work either)
Steven Parker
231,269 PointsSteven Parker
231,269 PointsYour declaration is fine for task 2, you only need to add the prefix to where the increment is done.
For task 3, they will get more specific about how it should be declared.