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 2/3

The only error I'm given is "Bummer: Try again!". Also the editor doesn't seem to want to work properly for this challenge either. Very frustrating not knowing what's even causing the code not to run.

racecar.py
class RaceCar:

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

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

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

3 Answers

boi
boi
14,241 Points

Heyooo Aaron!, You ALMOST got it;

class RaceCar:

    def __init__(self, color, fuel_remaining, **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):  # incorrect mehtod name "runlap" XD
        self.fuel_remaining -= (length * 0.125)
        self.laps += 1

LOL, you were only missing an underscore in the name of the method XD, your code is fine Well done This is a little silly.

Did this work?

Aaron Wilks , sorry that is for the next part of the code challenge where you cannot change the value of instances in ' RaceCar'

and you're missing self.laps = 0

class RaceCar:

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

        for key, value in kwargs.items():
            setattr(self, key, value)
            self.laps = 0 ####here

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

Wait, why does self.laps belong in the for loop as well as the init?