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 trialMarco Koopman
5,290 Pointsfuel_remaining isnt changing (wrong scope??)
Hey!
I'm stuck on this assignment, I don't really understand how to get certain variables I guess. It seems I can't change fuel_remaining, it always stays the same and I'm wondering what I'm doing wrong.
class RaceCar:
laps = 0
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):
RaceCar.laps += 1
self.fuel_remaining = (length * 0.125)
1 Answer
Jennifer Nordell
Treehouse TeacherHi there, Marco Koopman! You're doing terrific and you clearly understand how to set the value of a variable. But you forgot something tiny here (you're literally off by one character). Every time we run a lap we want to reduce the amount of fuel remaining by a certain amount. Makes sense, right? We run a lap and now we have less fuel. Each time you run a lap, you're setting the fuel_remaining
to the same number so it never changes.
You wrote:
self.fuel_remaining = (length * 0.125)
But you meant to write:
self.fuel_remaining = self.fuel_remaining - (length * 0.125)
Or in shorthand:
self.fuel_remaining -= (length * 0.125)
These will reduce the amount of fuel remaining and set the fuel_remaining
value to the now reduced value.
Hope this helps!