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

Object Oriented Python: Master Class Task # 2--What am I missing?

I assume I'm following the instructions for creating a "run_lap" method for this RaceCar class code close enough, and have tried adding extra attributes and arguments to the rest of the code I first put down in Task#1, based on what I'm seeing in the instructions. But it keeps telling me "Bummer: Try again!" I'm not getting any more feedback then that as to what the issue is. What am I missing in the code block for the "run_lap" method? Is there anything else I'm missing? If anyone can explain, or just give me a hint, I'd appreciate it. Thank you.

Michael

racecar.py
class RaceCar:
    color = "My Color"
    fuel_remaining = 10
    laps = 0

    def __init__(self, color, fuel_remaining=10, laps=0, **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):
        length = int(length)
        fuel_remaining = self.fuel_remaining - (length * 0.125)
        return fuel_remaining and self.laps += 1

1 Answer

volhaka
volhaka
9,875 Points
  1. In the method run_lap() you need to reduce the fuel_remaining attribute , it means you should reduce self.fuel_remaining self.fuel_remaining = self.fuel_remaining - (length * 0.125)
  2. method def run_lap() should not return anything, so increment self.laps in the method run_lap() body, not in the return statement

Thank you for your reply, Mr. Volha. I was overthinking the instructions at first, but the solution ended up being rather simple and understandable. I wonder whether the full code I made could be simpler still, and will probably be going back to it to practice on my own in the future. Thank you once again for your feedback. Take care.

Michael