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

Even though the laps attribute is inside the __init__ method, it's still erroring out..

Even though the laps attribute is inside the init method, it's still erroring out..

racecar.py
class RaceCar:

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

1 Answer

Hi, there!

Your code is so close!

The problem is in this line of your code.

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

When you write arguments there is an order you must follow. If you have these as arguments you want to write for example self, code, x = 0, *args, **kwargs

First, comes just regular arguments like self or code After that comes arguments that are assigned with value like x = 0 Then, *args comes after that Lastly **kwargs comes at the end.

Consequently, the order for the example I wrote would be

    def __init__(self,  code, x = 0, *args, **kwargs):

You can not mix these orders.

Your **kwargs is at the end which is very good, but your laps = 0 is written before fuel_remaining.

Hope this explanation was helpful, leave a comment if my explanation is confusing.