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 trial

Python Object-Oriented Python Instant Objects Master Class

Ojidur Rahman
Ojidur Rahman
2,201 Points

How to reduce fuel_remaining? Any syntax errors?

my second method seems to be having issues (run_lap)

racecar.py
class RaceCar:
    laps = 0

    def __init__(self, color, fuel_remaining, laps, **kwargs):
        self.color = color
        self.fuel_remaining = fuel_remaining
        self.laps

        for key, value in kwargs.items():
            setattr(self, key, value)

    def run_lap(length):
        self.fuel_remaining - (length * 0.125) = fuel_remaining
        return laps + 1 = laps

Just mind that the equal sign in the variable assignment doesn't mean that the variable is EQUAL TO the thing to be assigned. You must put the variable on the left of the equal sign and the assignment on the right. The variable assignment is analog to putting (for example) apples into a box. The box has to always be on the left and the apples on the right. Otherwise, Python will assume that you are putting your box into your apples. With mathematical operations is the same. You have to operate on the right to assign the result to the variable on the left. Hope this helps! ;-)

2 Answers

Clayton Perszyk
MOD
Clayton Perszyk
Treehouse Moderator 48,850 Points
def run_lap(length): # 1
        self.fuel_remaining - (length * 0.125) = fuel_remaining # 2
        return laps + 1 = laps # 3

1) pass self 2) assignment should happen on the left hand side 3) a. laps should be an attribute (i.e. self.laps) b. no return, just increment laps c. assignment should happen on the left hand side

Ojidur Rahman
Ojidur Rahman
2,201 Points

Thanks for answering. I included your changes but it is still an error?

class RaceCar:
    laps = 0

    def __init__(self, color, fuel_remaining, laps **kwargs):
        self.color = color
        self.fuel_remaining = fuel_remaining
        self.laps = laps

        for key, value in kwargs.items():
            setattr(self, key, value)

    def run_lap(self, length):
        fuel_remaining = self.fuel_remaining - (length * 0.125)
        laps = self.laps + 1
Clayton Perszyk
Clayton Perszyk
Treehouse Moderator 48,850 Points

HI Ojidur,

couple changes still required:

class RaceCar:
    laps = 0 # remove this 

    def __init__(self, color, fuel_remaining, laps **kwargs): # remove laps
        self.color = color
        self.fuel_remaining = fuel_remaining
        self.laps = laps # set to zero

        for key, value in kwargs.items():
            setattr(self, key, value)

    def run_lap(self, length):
        fuel_remaining = self.fuel_remaining - (length * 0.125) # assign to self.fuel_remaining
        laps = self.laps + 1 # assign to self.laps
Ojidur Rahman
Ojidur Rahman
2,201 Points

THANKS CLAYTON!

Really helped :)