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

Aleksandar Stankovic
seal-mask
.a{fill-rule:evenodd;}techdegree
Aleksandar Stankovic
Python Development Techdegree Student 9,648 Points

Problem with the challenge (part 2/3).

Hello Guys, I am a little stuck in this challenge, I do not know how to add +1 to the "laps" attribute once the method "run_lap" is called. I tried many things, but I miss something obviously. My code is attached.

racecar.py
class RaceCar:
    laps = 0


    def __init__(self, color, fuel_remaining,laps=0, **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, lengt, laps):
        self.length = fuel_remaining - (length * 0.125)

1 Answer

Steven Parker
Steven Parker
231,269 Points

It looks like you have a few other issues as well:

  • the parameter name spelled "lengt" instead of "length"
  • the reference to "fuel_remaining" needs a "self." prefix
  • the fuel calculation should update the remaining fuel instead creating a new "length" attribute

And adding to the laps can be done like this:

        self.laps += 1
Aleksandar Stankovic
seal-mask
.a{fill-rule:evenodd;}techdegree
Aleksandar Stankovic
Python Development Techdegree Student 9,648 Points

Steven, thank you so much for the advice. It was very helpful.

However t may sound, but with this challenge I completely understood the logic behind (self.).
Sometimes challenges are way to important not to be taken seriously. Thanks again.