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

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
14,242 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.

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.

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!