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

Tobias Sanden
Tobias Sanden
2,324 Points

Any advice on why i can't run this code?

This is part of the racecar.py challenge. Tried everything possible but do not seem to get it right. Any help would be welcome!

racecar.py
class RaceCar:
    laps=0

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

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

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

2 Answers

Alex Koumparos
seal-mask
.a{fill-rule:evenodd;}techdegree
Alex Koumparos
Python Development Techdegree Student 36,887 Points

Hi Tobias,

You have a couple of problems here. First you have inconsistent indentation in your class (laps is indented 4 spaces, your first method is indented 3 spaces and your second method is indented 2 spaces). PEP 8 recommends that all indentation be at 4 spaces, but the exact amount is less important than that all indentation within an entity (e.g., a class) be consistent.

Second, your __init__() method signature is not consistent with what the challenge requires. It asks for the following named parameters: color and fuel_remaining. You have provided three named parameters: color, fuel_remaining, and laps.

Hope that clears everything up.

Cheers

Alex

Tobias Sanden
Tobias Sanden
2,324 Points

Thank you for the help, Alex! indentation probably got messed up with all the attempts and I did not realize it... Cheers