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

help! why is this not correct?

why is this not correct?

racecar.py
class RaceCar:

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

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

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

6 Answers

code:

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
        def run_lap(self,length):
            self.fuel_remaining = self.fuel_remaining -(length*0.125) 
            self.laps += 1

thanks a lot :)

Steven Parker
Steven Parker
231,275 Points

The "run_lap" method does not need an explicit "return", it only needs to update the attributes.

Also, when you do use "return", it immediately ends the method, so no code after it will ever be executed.

Hello Steven, I tried removing return. "it says make sure you set laps to 0". I changed it to laps == 0. now it says "try again". something is not right. the task is : " OK, now let's handle the racecar running laps. Add a laps attribute to the RaceCar class and set it to 0. Add a method named run_lap. It'll take a length argument. It should reduce the fuel_remaining attribute by the length argument multiplied by 0.125 (length * 0.125). Also, increment the laps attribute by 1 each time the run_lap method is called."

Steven Parker
Steven Parker
231,275 Points

There should not be a "laps" argument. Just set "self.laps" to 0 internally in the init.

Stephen, can you look at my code and tell me what's wrong with it? class RaceCar: def init(self, color, fuel_remaining, **kwargs): self.color = color self.laps = 0 self.fuel_remaining = fuel_remaining for key, value in kwargs.items(): setattr(self, key, value)

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

Thanks!

I am so STUPID!!! 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

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

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 def run_lap(self,length): self.fuel_remaining = self.fuel_remaining -(length*0.125) self.laps += 1 Still trying without a break

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)
  def run_lap(self, length):
    self.fuel_remaining = self.fuel_remaining  - (length*0.125)
    self.laps = length +=1

I am in tears...crying now because I've tried everything and nothing works....maybe I can skip this challenge and still get my badge?

Here's another try that "went wrong": 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)
  def run_lap(self, length):
    self.fuel_remaining = self.fuel_remaining - (length * 0.125)
    self.laps +=1
    print(run_lap)
Steven Parker
Steven Parker
231,275 Points

If you're still having trouble, create a new, fresh question instead of posting "answers" to a previous one. :see_no_evil:

if it's still not solved compare it to my answer!