I'm in. The line says that I have problems in line 11:

taberror traceback

I can not understand where the problem is, I indent, but something prevents me from starting the program normally. By the way , the code itself :

print('Test Program') print("This is my proga!") name = input("Ваше имя: ") print(name, ", добро пожаловать в темный мир.") answer = '' while answer != 'End': answer = input("Ты бы хотел взять какое-нибудь оружие? (Y/N/End): ") if answer == 'Y': print("1-Пулемёт") print("2-Гранатомет") print("3-Однозарядный пистолет") print("4-АА-12") answer2 = input("Ваш ответ:") if answer2 == '1' or answer2 == '2': print("Хороший выбор.") elif answer2 == '3': print("Плохой выбор, возьми другое.") else: print("Великолепный выбор.") elif answer == 'N': print("Ты пацифист? Круто!") else: print("Ладно, подумай ещё.") 
  • four
    9th line - indent 4 spaces, 10th - indent 3 spaces. Do not ask questions here in this tone. - andy.37
  • four
    Only use spaces to specify indents. And make sure that their number is the same for the generated code blocks. - mkkik
  • @ andy.37 question with the title "Where did it come from: TabError: inconsistent use of tabs and spaces in indentation" is quite relevant to the Stack Overflow. Many programmers, starting to learn Python, may encounter this problem when copying examples from different sources. Not every editor is configured to use spaces for indents by pressing the Tab key. The usefulness of a question is not complexity, but how many people it will help (example: the question about print and parentheses in Python 3 were visited by hundreds of thousands of people ) - jfs
  • Thank you, everything worked out for me, I just replaced the spaces with tabs - Yaroslav_Fox

1 answer 1

Yandex Translator translates "TabError: inconsistent use of tabs and spaces in indentation" as:

TabError: inconsistent use of tabs and spaces in indents

Which indicates that your indents (space to the left of the code) use both spaces and TAB .

Do not mix spaces and tabs. A code that mixes spaces and tabs may look different in different editors (tabs may correspond to different numbers of spaces). Visually, the indents that you see may differ from the indents, as their original author of the code intended. In turn, this may differ from how the python interpreter sees these indents . Python 3 automatically TabError throws out. In Python 2, it was necessary to -tt command line option to enable checking.

Padding matters in Python . The PEP-8 Code Style Guide for Python recommends using 4 spaces for each indent:

Use 4 spaces per indentation level.

Set your IDE to use spaces for indents by pressing the Tab ↹ key. There are tools that automatically format your code (autopep8, yapf ). You can enable them in your IDE so that they are executed each time the code is saved.

In the new code, tabs for indents should not be used. Tabs can be used in old code that already uses tabs.

The syntactic significance of indents in Python ensures that what you see is what you get :

 if some_condition: if another_condition: do_something(fancy) else: this_sucks(badluck) 

Compare with C code, indentation in which is misleading:

 /* Warning: XXX bogus C code! */ if (some condition) if (another condition) do_something(fancy); else this_sucks(badluck); 

Here else belongs to the internal if , despite the formatting. Errors of this kind are also encountered in practice ( "goto fail" in iOS ). In gcc 6, a new warning has been added -Wmisleading-indentation . Unlike Python, in C it is more difficult for the compiler to determine if the indent is correct or not (heuristics must be used).