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 trialAmmar Jalabi
Python Development Techdegree Graduate 12,493 PointsIs something wrong with my code ?
To me my code seems to be correct, I'm not getting what's this code challenge expecting me to do ? I fulfilled the tasks , what's left ?!
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 = self.laps + 1
RaceCar = RaceCar(color = None, fuel_remaining = 100, laps = 0)
2 Answers
Mark Sebeck
Treehouse Moderator 37,905 PointsYou need to set self.laps = 0 in the init. Also delete the last line where you create an instance. It's not needed for this challenge. Good job. Minor mistakes.
Ammar Jalabi
Python Development Techdegree Graduate 12,493 PointsThank you for answering
Juan Olivares
2,890 PointsJuan Olivares
2,890 PointsHello mark, How come we don't place ,laps = 0, inside the () of init and have self.laps = laps? wouldn't that make laps = 0 as default?
Mark Sebeck
Treehouse Moderator 37,905 PointsMark Sebeck
Treehouse Moderator 37,905 PointsExcellent question Juan! In programming there are many ways to do the same functionality. The answer is you can. Another question you have to ask is why would you want to? Maybe you would want to start on a lap other than 0? If so then you could add lap as an argument to the constructor and set it's default to zero. I tried your suggestion for fun and it did pass the challenge
Remember you always want to keep it simple so if you don't need to dynamically change the start lap you wouldn't need to add it as an argument.
Great question. I love a challenge. Keep looking for ways to improve code. You learn so much more that way.
Juan Olivares
2,890 PointsJuan Olivares
2,890 PointsThanks for the answer!