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 trialJoshua Thao
6,439 Pointslaps is in my init method what is going on here?
challenge says to add laps to init method which I did. It just says Try Again when I try to submit
class RaceCar:
laps = 0
def __init__(self, color, laps, fuel_remaining, **kwargs):
self.color = color
self.laps = laps
self.fuel_remaining = fuel_remaining
for k, v in kwargs.items():
setattr(self, k, v)
def run_lap(self, length):
self.fuel_remaining -= (length* 0.125)
self.laps += 1
1 Answer
Jennifer Nordell
Treehouse TeacherHi there, Joshua Thao ! Looks like you're doing pretty terrific from what I'm seeing Maybe it will help to think about this in a more "real world" sort of way. Assuming that a factory produces a new race car, at the time that racecar leaves the factory how many racetrack laps has it run? Zero. It's never been on the racetrack yet.
So instead of setting laps as an attribute higher up in the class to zero. Just set it to 0 in the __init__
. Which means you don't need to pass in the number of laps at the time of creation. We wouldn't create a new racecar and automatically credit it as having done 5 laps. That would be silly.
So as for your __init__
I'm expecting to see something more like:
class RaceCar:
def __init__(self, color, fuel_remaining, **kwargs):
self.laps = 0
# other code omitted for brevity
Hope this helps!