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 trialjessechapman
4,088 Pointsrun_lap method in Object-Oriented Coding challenge
The def init method words fine, but I have hit a wall with the run_lap method portion this challenge. The challenge specifies that length should be passed as an argument to the method, that it should reduce fuel_remaining by .125 times the length, and that it should increase the laps by one. I have tried including all of these as parameters for the run_laps method, as well as returning the values using a tuple. Unfortunately, after many variations, I can't see to identify the problem. In every case, the error message is only "Bummer: Try again!"
class RaceCar:
def __init__(self, color, fuel_remaining, laps, **kwargs):
self.color = color
self.fuel_remaining = fuel_remaining
self.laps = 0
for k, v in kwargs.items():
setattr(self, k, v)
def run_lap(self, fuel_remaining, laps, length):
self.laps += 1
self.fuel_remaining -= (length * 0.125)
1 Answer
Steven Parker
231,248 PointsIt looks like you added a "laps" argument to __init__
after passing task 1, but it should not be changed in task 2.
Also, the "run_lap" method is only intended to take a length argument. It won't take "fuel_remaining" or "laps" as arguments. Those are internal variables that you already have correctly referenced using the "self." prefix.