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 trialvincent juma
1,159 PointsHello, 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
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
Treehouse Moderator 68,441 PointsYou 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" inrun_lap
method - reference to parameter
length
should belength
and notself.length
Post back if you need more help. Good luck!!
vincent juma
1,159 Pointsvincent juma
1,159 PointsWoow, I do appreciate this.