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 trialKabir Gandhiok
12,553 PointsNot sure how to do the second part of this challenge: increment an attribute everytime a method is called
I tried adding while and for loops, tried using if statements to increment laps by 1 everytime run_lap() is called, tried using self.class.laps +=1 which I got from google, but nothing seems to work, what am I missing or doing 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):
if self.fuel_remaining:
fuel_remaining - (length * 0.25)
1 Answer
Steven Parker
231,269 PointsYou're close, but I spot a few issues:
- you wrote "salf" (with an "a") instead of "self" where you increment laps
- you modified length instead of fuel_remaining when you recalculate the fuel
- the challenge did not ask for a length property
- run_lap doesn't need to return anything
Kabir Gandhiok
12,553 PointsHey, thanks Steven! I modified fuel_remaining and now it works!
Kabir Gandhiok
12,553 PointsKabir Gandhiok
12,553 PointsI fixed the code above and I think it passes in the shell based on what output i get, yet I dont know why it doesnt pass in the challenge, here's what i did:
class RaceCar: laps = 0
on output i get: