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

jessicamurr
jessicamurr
3,313 Points

Can someone please tell me where I am going wrong with my code? OOP Master Class challenge part 2

I got past the first part of the challenge, but then I got the error to add that laps = 0, which I did. Now it's saying "try again!" without saying where I am going wrong. Can someone please explain what is wrong with it? Thank you!

Here are the instructions: "OK, now let's add a method named run_lap. It'll take a length argument. It should reduce the fuel_remaining attribute by length multiplied by 0.125. Oh, and add a laps attribute to the class, set to 0, and increment it each time the run_lap method is called."

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

    def run_lap(self, length):
        self.fuel_remaining -= length *0.125
        self.laps += 1

1 Answer

Steven Parker
Steven Parker
231,268 Points

You're really close! But "laps" should not be a required argument to create an instance (it's always set to 0 internally).

jessicamurr
jessicamurr
3,313 Points

I just got it to work! For the 2nd part of the challenge, I had to set laps to 0, but the 3rd part of the challenge said that we could remove it just like you said. Thank you for replying!