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

nakalkucing
nakalkucing
12,964 Points

I am stuck on OOP Master Class: Challenge Task 2 of 3 Help Please!

The instructions are: "Vrroom! 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." I have looked through the other questions about this challenge and made several of their suggested changes, but I still get bummered. I would really appreciate any help. Thanks in advance. :)

racecar.py
class RaceCar:

    def __init__(self, laps = 0, 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):
        self.fuel_remaining -= length * 0.125
        self.laps += 1
pet
pet
10,908 Points

After looking at your code nakalkucing I could fix mine!

2 Answers

Steven Parker
Steven Parker
216,057 Points

The "laps" value should always be set to 0 in a new instance. It should not be one of the arguments required to create a new instance.

class RaceCar: laps=0 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)

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

Hi Pierre ILYAMUKURU. Are you trying to answer my question or are you asking a question about your code? If you've got a question I'd be glad to help. Happy coding! :)