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

Prisca Egbua
Prisca Egbua
1,167 Points

This code looks okay but I get "TabError: inconsistent use of tabs and spaces in indentation"

The problem occurred when I try to add a new method run_lap that takes a length as an argument, reduces the fuel_remaining attribute by length multiply by 0.125, and increment lap attribute. Please help?

class RaceCar:
    def __init__(self,color,fuel_remaining,**kwargs):
        self.laps = 0
        for key,value in kwargs.items():

    def run_lap(self,length):
        self.length = length
        self.fuel_remaining = self.fuel_remaining - (self.length * 0.125)
        self.laps = self.laps + 1
Mariah Winifred Palangpour
Mariah Winifred Palangpour
11,795 Points

It would be awesome if the treehouse challenge workspace could adapt to allow you to set tabs to use four spaces, like you can do in other editors, and/or somehow highlight non-matching tab and spaces use. I agree that it is extremely frustrating when you've written solid code otherwise and can't see what you've done wrong. I've always used tab and it seems like the code challenge editor always uses 4 spaces when it indents for you after the creation of a block. I understand that spacing is super important in Python, but having to copy/paste code challenge code into workspaces or another editor just to figure out the otherwise non-visible difference between tabs and spaces is interrupting my ability to get through the Python courses with speed.

1 Answer

Jennifer Nordell
Jennifer Nordell
Treehouse Teacher

Hi there! The error you are getting is indicative of mixing tabs and spaces in the same file, which you may not do in Python. You may not indent with tabs on one line and then indent with spaces on the next. This is built-in to Python and it's because Python is dependent upon whitespace to know what constitutes the beginning and ending of a block of code. Go back through your code and make sure you either use all tabs or all spaces for indentation.

Hope this helps! :sparkles: