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 trialSoizic Demetz-Lovell
3,005 PointsKeep getting Bummer error
Hi again everyone! I figured out my last problem was just an indentation issue, fixed it, and my code passed the first task. Now I'm stuck trying to figure out why I keep getting an error on the second task as well! Here's the question: 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'm thinking it's something simple again that I'm just not seeing, but I can't go on until I figure it out. Thanks again and in advance!
class RaceCar:
def __init__(self, color, fuel_remaining, **kwargs):
self.color = color
self.fuel_remaining = fuel_remaining
self.laps = 0
for key, value in kwargs.items():
setattr(self, key, value)
def run_lap(self, length):
self.fuel_remaining -= length * 0.125
self.laps = self.laps + 1
Soizic Demetz-Lovell
3,005 PointsHm, still not working on my end.. No idea what's going on! Thanks a ton for your input Oszkar!
Oszkár Fehér
Treehouse Project ReviewerIn this case you should write to treehouse team because this solution works.
3 Answers
Steven Parker
231,261 PointsThis code looks good, and when I paste it directly into the challenge, it passes.
Try again?
Oszkár Fehér
Treehouse Project ReviewerIt's working for me as well i tried 3 times, no errors.
Soizic Demetz-Lovell
3,005 PointsWell after a ton of tries yesterday I ended up just leaving it hoping it would fix itself. Tried it first thing this morning and it finally went through. No idea what that was about, but glad it finally worked! Thank you for trying it out! :)
Justin Walters
PHP Development Techdegree Student 18,894 PointsI have the same solution and the same issue and it has been driving me crazy. Why isn't my code acceptable?
Steven Parker
231,261 PointsThere's always a slight chance your solution may be a bit different. Try creating a new fresh question and post your code there. Starting it from inside the challenge with the "get help" button should post your code with correct formatting (like on this question).
Chad Goldsworthy
4,209 PointsJust for anyone still struggling with this, I think I managed to find the issue. I tried all the code other people posted and said worked, but it did not work for me (and it seems there were many people having the same issue).
I ran it through my IDE and realised the length*0.125 in the run_lap method was causing a TypeError: unsupported operand type(s) for -=: 'str' and 'float'
So, when assigning fuel_remaining in the init method, you should convert it to a float as well, like: self.fuel_remaining = float(fuel_remaining)
I say "you should" lightly though, I'm no expert but it's just what fixed the issue for me.
This is the code that eventually worked for me:
class RaceCar:
laps = 0
def __init__(self, color, fuel_remaining, **kwargs):
self.color = color
self.fuel_remaining = float(fuel_remaining) # <-- this is what fixed it for me,
# adding the float() method
for key, value in kwargs.items():
setattr(self, key, value)
def run_lap(self, length):
self.fuel_remaining -= (length * 0.125)
self.laps += 1
Steven Parker
231,261 PointsIt sounds like you may have been passing in a string when you created the test instance. I would expect the validation mechanism to pass in a number, and I can confirm that the code does pass without the explicit conversion.
Oszkár Fehér
Treehouse Project ReviewerOszkár Fehér
Treehouse Project ReviewerHi Soizic Demetz-Lovell, I copy-pasted your code and it passes both challenges. Your code is working fine.