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

edward suggs
edward suggs
1,346 Points

hello i am still stuck on this task in OOP the video doesn't help me i need tips

should laps = 0 be self.laps = 0 what else is wrong with my code?

racecar.py
class RaceCar:
    laps = 0 
    def __init__(self, color=None , fuel_remaining=None, **kwargs):

        self.color = color
        self.fuel_remaining = fuel_remaining

        for attribute, value in kwargs.items():
            setattr(self, attribute, value)



    def run_lap(self, length):

        self.fuel_remaining-= * 0.125
        self.RaceCar.laps + = 1 

1 Answer

Hi there,

Since you have run_lap, I'm guessing you're on the second step. That means your _init_ passed, so let's look at what we need to do to run_lap:

  • the fuel_remaining should be reduced by the length value multiplied by 0.125 - so, we need to add "length" in there.
  • we don't need the class name in the next line - just self.laps
  • we need to take the space out between the + and the =

That leaves us with something like this:

class RaceCar:
    laps = 0 
    def __init__(self, color=None , fuel_remaining=None, **kwargs):

        self.color = color
        self.fuel_remaining = fuel_remaining

        for attribute, value in kwargs.items():
            setattr(self, attribute, value)



    def run_lap(self, length):
        self.fuel_remaining -= length * 0.125
        self.laps += 1

Good luck!