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

Racecar challenge part 1

Can someone give me a hint or some guidance for where I am going wrong.

racecar.py
Class RaceCar:
    def __init__(self, color, fuel_remaining,**kwargs):
        self.color = color
        self.fuel_remaining = fuel remaining
        for self, key, value in kwargs.items():
            setattr (self, key, value)

3 Answers

Steven Parker
Steven Parker
231,268 Points

Very close! But:

  • like most Python keywords, "class" should be all lower case
  • "fuel remaining" should be "fuel_remaining" (underscore instead of space)
  • the "items" method returns only keys and values (no "self")
Steven Parker
Steven Parker
231,268 Points

On that third hint, the correction would look like this (with no "self"):

        for key, value in kwargs.items():

What is wrong here?

class RaceCar:
    def __init__(self, color, fuel_remaining,**kwargs):
        self.color = color
        self.fuel_remaining = fuel_remaining
        for self, key, value in kwargs.items():
            settattr(key, value)

It is still not running

class RaceCar:
    def __init__(self, color, fuel_remaining, **kwargs):
        self.color = color
        self.fuel_remaining = fuel_remaining
        for key, value in kwargs.items():
            setattr(key, value)

        ```
Steven Parker
Steven Parker
231,268 Points

But you do need "self" in the "setattr" call:

            setattr(self, key, value)