Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Object-Oriented Python Instant Objects Master Class

Evert-Jan van Dijk
Evert-Jan van Dijk
937 Points

Please, tell me what's wrong about this class?

In the RaceCar challenge in the python oop basics I'm getting the "Try again!" feedback over and over again. Even after making multiple changes to my class, like adding a colon after for attribute, value in kwargs.items(): and adding "self" before the attributes. I don't know what else to do. Please take a look at my code in the attachment and give me some feedback that I can actually do something with.

racecar.py
class RaceCar:
    def __init__(self, color, fuel_remaining, **kwargs):
        self.color = "red"
        self.fuel_remaining = "30 litres"

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

redbull = RaceCar()

redbull.color = "purple"
redbull.fuel_remaining = "25 litres"

2 Answers

boi
boi
8,670 Points

There are three parts of that challenge, I assume you're stuck on the first part? I also assume that your code I'm reading is supposed to be as it is? In that case, your attributes set are all wrong

class RaceCar:
    def __init__(self, color, fuel_remaining, **kwargs):
        self.color = "red" 👈# Why set "red" here? Did the challenge tell you to set it to "red"?
        self.fuel_remaining = "30 litres"👈# Same case here.

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

redbull = RaceCar()👈#Don't call stuff in the challenge, preserve that for the teacher

redbull.color = "purple"👈#Don't call stuff in the challenge, preserve that for the teacher
redbull.fuel_remaining = "25 litres"👈#Don't call stuff in the challenge, preserve that for the teacher

You're in the right direction but with the wrong tools, If you can't understand my hints, msg me here, and I'll gladly help you.

Evert-Jan van Dijk
Evert-Jan van Dijk
937 Points

Correct, I'm at the first part of the challenge. Thanks, for your suggestions! I think I get what you're telling me about setting the attributes. However the challenge does actually tell me to set the values in an instance. I'll let you know tomorrow, what progress I've made.

Evert-Jan van Dijk
Evert-Jan van Dijk
937 Points

Thanks again, I got distracted by the part of task description that says: "Set these as attributes on the instance." Now that I've adjusted the RaceCar class and left out the calling of the class as an instance it's alright!