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 trialKhaled Issa
2,621 Pointshelp! why is this not correct?
why is this not correct?
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
Ritik Parihar
2,169 Pointscode:
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
Steven Parker
231,271 PointsThe "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.
Khaled Issa
2,621 PointsHello 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
231,271 PointsThere should not be a "laps" argument. Just set "self.laps" to 0 internally in the init.
Lynn Collins
10,080 PointsStephen, 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!
Lynn Collins
10,080 PointsI 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
Lynn Collins
10,080 Pointsclass 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
Lynn Collins
10,080 Pointsclass 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?
Lynn Collins
10,080 PointsHere'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
231,271 PointsIf you're still having trouble, create a new, fresh question instead of posting "answers" to a previous one.
Ritik Parihar
2,169 Pointsif it's still not solved compare it to my answer!
Khaled Issa
2,621 PointsKhaled Issa
2,621 Pointsthanks a lot :)