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

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
231,269 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! :)