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

Karen Ku
Karen Ku
2,194 Points

I don't know How to fit my code..

Is there something wrong in my code?

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

        for key, value in kwargs.items():
            setattr(self, key, value)
    def run_lap(self,length):
        self.fuel_remaining -= length*0.125
        laps += 1

1 Answer

Jon Hockley
Jon Hockley
3,781 Points

Just to nudge you in the right direction; you're not quite incrementing the laps class attribute correctly, but you're very close! Check back in the videos, or do a quick Google search on how to change class attributes in Python.

I think it's better to nudge you rather than directly tell you the answer when you're so close. Once you find out what's wrong you won't forget it again!

Hasan Ahmad
Hasan Ahmad
6,727 Points

Thx that helped, classes are so specific about the self keyword. Does the self keyword make a variable a local variable Jon?

Jon Hockley
Jon Hockley
3,781 Points

Self is just a reference to the object. Going back to the code in the original question, if you were to create two RaceCar objects; x and y and then call run_lap on x, then self will only reference RaceCar x and not y.

Hope that makes sense!

Hasan Ahmad
Hasan Ahmad
6,727 Points

Makes sense. (I never asked this question btw)

Jon Hockley
Jon Hockley
3,781 Points

Ah Sorry! I thought you were the OP :)

I've edited my answer to be a bit more general; glad I could help!