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 trialRitik Parihar
2,169 Pointshow do i call this "run_lap" method and increment "laps" attribute by 1 when its called help!
i don't know how to call the run_laps method and when its called how to increment the run_laps method
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,laps)
self.laps = 0
def run_lap(self,length):
length = fuel_remaining - (length*0.125)
return self.length
if self.lenght = true:
run_lap += 1
1 Answer
Steven Parker
231,269 PointsIt looks like there's a few issues to resolve:
- check indentation — the "def" line should start in the same column as the other "def" line in the class
- the "
self.
" prefix should not be used on parameters - but the "
self.
" prefix is needed on the class attributes (like "fuel_remaining") - the "run_lap" method does not need to "return" anything
- check spelling ("lenght " instead of "length")
- the increment does not need a conditional ("if")
- the item to be incremented is "self.laps" instead of "run_lap"
Ritik Parihar
2,169 PointsRitik Parihar
2,169 Pointsclass 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,laps) self.laps = 0 def run_lap(self,length): length = fuel_remaining - (length*0.125) self.laps += 1
i've done this but it still shows error!
Steven Parker
231,269 PointsSteven Parker
231,269 PointsWhen posting code to the forum, use Markdown formatting to preserve the appearance, particularly indentation!
But it looks like you have not yet implemented several of the suggestions.