Python Object-Oriented Python Instant Objects Master Class

victor escarcega
victor escarcega
7,599 Points

using a method, not sure what I am missing here

I think I should add self somewhere here. Not sure where, can you provide a simple explanation as to when to add self and when not to add self?

racecar.py
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):
        self.length = length
        return fuel_remaining -= (self.length * 0.125)
        return laps += 1

1 Answer

Jassim Al-Hatem
Jassim Al-Hatem
12,353 Points

You're doing too much here mate. And for some reason, you have two return statements when the question didn't even ask you to return anything (return statements can only be called once).

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):
        self.fuel_remaining -= (length * 0.125)
        self.laps += 1
victor escarcega
victor escarcega
7,599 Points

thank you, I must have been over thinking it.