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

Hello, everyone.Am caught up with this error on my code and I'm not sure why it's wrong. Kindly help me see it.

I have added a method named run_lap, and it takes a length argument. It should reduce the fuel_remaining attribute by length multiplied by 0.125.

And it should add a laps attribute to the class, set to 0, and increment it each time the run_lap method is called.

But I get this error Bummer: Try again

racecar.py
class RaceCar:

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

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

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

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,426 Points

You are close. There are 3 mistakes in your current code:

  • need to add parameter laps=0 to __init__ method
  • need to increment the attribute self.laps not "laps" in run_lap method
  • reference to parameter length should be length and not self.length

Post back if you need more help. Good luck!!

Woow, I do appreciate this.