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

Dave StSomeWhere
Dave StSomeWhere
19,822 Points

Object Oriented Python - Cannot pass challenge - class RaceCar

The challenge (step 2 of 3) asks:


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.

The init function was done is step 1 and passed.

I added the laps attribute line to the init function.

Here's my code and it appears to test fine locally for executing the run_lap() method. The challenge just says Bummer, Try Again - no clue as to what failed.

class RaceCar:

    def __init__(self, color, fuel_remaining, **kwargs):
        self.laps = 0
        self.color = color
        self.fuel_remaining = fuel_remaining
        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

Jason Anders
Jason Anders
Treehouse Moderator 145,624 Points

Hi Dave,

Your code looks fine!

There may have been a temporary glitch in the challenge (this does happen occasionally).

Restart the challenge and copy/paste the code snippet you have above into a fresh challenge and it will all pass (it did for me).

Nice work!! :) :dizzy:

Dave StSomeWhere
Dave StSomeWhere
19,822 Points

Thanks, Jason it worked - things were flaky earlier today were sometimes the embedded code in the teachers notes and challenges did not show up.