Python : Taberror
Python : Taberror
I have one Estonian script, but It gives me error:
Sorry: TabError: inconsistent use of tabs and spaces in indentation (function sheet1.py, line 8)
[Finished in 0.2s with exit code 1]
and code is:
import sys
import datetime
end = False
while end == False:
def contin01():
print("Kas soovid jätkata?")
exit = input("Vali [1] - JAH // Vali [2] - EI: ")
if exit[0] == "1":
print("********* Beginning of Line ********* ")
elif exit[0] == "2":
sys.exit()
def sina():
nimi = input("Kirjuta enda nimi: ")
def guest_name():
Guest_Name = input("Sisesta kliendi nimi: ")
def guest_arrival():
Arrival = input("Sisesta kliendi saabumiskuupäev: ")
def guest_dep():
Departure = input("Sisesta kliendi lahkumiskuupäev: ")
def room():
Room_number = input("Sisesta kliendi toa number ")
def special():
req = input("Kirjuta kliendi erisoovid, kui puuduvad pane "-": ")
def WU():
wake = input("Kirjuta mis kell soovib klient äratust")
def date():
päev = datetime.datetime.now().strftime("%d-%m-%Y T%H:%M")
can't find the problem - tried deleting and trying again but nothing changes
1 Answer
1
Normalize your source code. "Use 4 spaces per indentation level" according to Python PEP8. If you mix tabs and space within one indentation context (e.g. function), you will get the warning, you mentioned.
The following source code is badly formatted (where <SPACE>
stands for a space character and <TAB>
stands for the horizontal tab):
<SPACE>
<TAB>
def func(x):
<SPACE><SPACE><SPACE><SPACE>if x == 6:
<TAB><TAB>return 1
<SPACE><SPACE><SPACE><SPACE>return 42
will give the following error:
File "test.py", line 3
return 1
^
TabError: inconsistent use of tabs and spaces in indentation
whereas the following program is correct:
def func(x):
<SPACE><SPACE><SPACE><SPACE>if x == 6:
<SPACE><SPACE><SPACE><SPACE><SPACE><SPACE><SPACE><SPACE>return 1
<SPACE><SPACE><SPACE><SPACE>return 42
BTW, while end == False
should be written while not end
and requires an additional indentation level in the following line.
while end == False
while not end
Also worth mentioning that functions ideally should not be defined within a loop
– cricket_007
Jun 29 at 23:08
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Everything under the while loop at the top isn't even intended correctly in the question
– cricket_007
Jun 29 at 22:58