• Register
0 votes
25 views

Problem:

I am a newbee in python programming. I was doing my coding practice. I wrote some codes like :
class MyCar:
    def __init__(self,rang,oil_remaining,**kwargs):
        self.rang=rang
        self.fuel_remaining=oil_remaining
        self.taps = 0
        for key,value in kwargs.items():
            setattr(self,key,value)

    def total_tap(self,length):
        self.length = length
        self.oil_remaining = self.oil_remaining - (self.length * 0.125)
        self.taps = self.taps + 1

but it shows me an error message like:

TabError: inconsistent use of tabs and spaces in indentation

The code seems right to me but I dont know why am I getting this type of errors. Please help me 

10 7 2
6,050 points

1 Answer

1 vote
 
Best answer

Answer:

Hello,The error you are getting is indicative of mixing tabs and spaces in the same file, which you should not do in Python. You might 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 of the beginning and ending of a block in codes.

 

So go back through your code and make sure you either use all tabs or all spaces for indentation, and write your code like:

 

class MyCar:
  def __init__(self,rang,oil_remaining,**kwargs):
    self.rang=rang
    self.fuel_remaining=oil_remaining
    self.taps = 0
    for key,value in kwargs.items():
      setattr(self,key,value)

  def total_tap(self,length):
    self.length = length
    self.oil_remaining = self.oil_remaining - (self.length * 0.125)
    self.taps = self.taps + 1

Happy coding

11 6 4
34,930 points

Related questions

0 votes
2 answers 335 views
335 views
Problem : I'm new to Python & trying to create an application in Python 3.2 and I use tabs all the time for indentation, but even the editor changes some of them into spaces and then print out "inconsistent use of tabs and spaces in indentation" when I try to run the program.
asked Oct 21, 2019 peterlaw 6.9k points
0 votes
1 answer 26 views
26 views
Problem: I am new to python and I have implemented the list in python and trying to access the list index but it getting me an error that is intend error by for loop don’t know what I am doing wrong in this code. I come from the C background so ... File "main.py", line 46 break ^ IndentationError: unindent does not match any outer indentation level Need someone to help me waiting for help!!
asked Jun 29 Gavin 15.3k points
0 votes
1 answer 59 views
59 views
PROBLEM: Python programming is new to me . I wrote a code which gives me following error: python indentationerror: unindent does not match any outer indentation level The code I wrote is: import sys def Function(x): result = 1 for i in range (1,x): result = result * i * i print ("Your factorial is ",result) return result print (Function(10))
asked Mar 18 LizzyM 6.1k points
0 votes
1 answer 114 views
114 views
Problem : When I try to compile my Python code below, I get below error “IndentationError: unindent does not match any outer indentation level” import sys def Factorial(n): # Return the factorial     myresult = 1     for j in range (1,n):         myresult = myresult * j     print "The factorial is: ",myresult     return myresult Why am I getting above error?
asked Jan 22 jwilliam 3.9k points
0 votes
1 answer 90 views
90 views
Problem : When I compile the Python code I get below error IndentationError: unindent does not match any outer indentation level
asked Oct 21, 2019 peterlaw 6.9k points