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 Object-Oriented Python Instant Objects Master Class

what 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"

racecar.py
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
Steven Parker
231,248 Points

Unfortunately, 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".

the 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
Steven Parker
231,248 Points

Your 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.

like 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
Steven Parker
231,248 Points

If 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.

awesome! thanks - got it that time - all the things need prefix - got it!