In my com. line writes that I have problems on line 11:
I can’t figure out where the problem is, I indent, but something prevents the program from running normally. By the way, the code itself :
print ('Test Program') print ("This is my proga!") name = input ("Your name:") print (name, ", welcome to the dark world.") answer = '' while answer! = 'End': answer = input ("Would you like to take any weapon? (Y / N / End):") if answer == 'Y': print ("1-Machine gun") print ("2-Grenade Launcher") print ("3-Single Shot Pistol") print ("4-AA-12") answer2 = input ("Your answer:") if answer2 == '1' or answer2 == '2': print ("Good choice.") elif answer2 == '3': print ("Bad choice, take another.") else: print ("Great choice.") elif answer == 'N': print ("Are you a pacifist? Cool!") else: print ("Okay, think again.")
Answer 1, authority 100%
Yandex Translator translates” TabError: inconsistent use of tabs and spaces in indentation “as:
TabError: inconsistent use of tabs and spaces in indentation
Which indicates that your indents (space to the left of the code) use both spaces and TAB .
Do not mix spaces and tabs. Code that mixes spaces and tabs may look different in different editors (tabs may correspond to a different number of spaces). Visually, the indentation you see may differ from the indentation as the original author of the code intended. In turn, this may differ from how the python interpreter sees these indents . Python 3 automatically
throws out. In Python 2, you needed the
-tt option command line
add to enable validation.
Use 4 spaces per indentation level.
Configure your IDE to use spaces for indentation on click on
Tab ↹ key. There are tools that automatically
will format your code (autopep8,
yapf , black ). You can them
enable in your IDE so they run on every save
In new code, indentation tabs should not be used. Tabs can
use in legacy code that already uses tabs.
The syntactic importance of indentation in Python ensures that what you see is
if some_condition: if another_condition: do_something (fancy) else: this_sucks (badluck)
Compare with C code where indentation is misleading:
/ * Warning: XXX bogus C code! * / if (some condition) if (another condition) do_something (fancy); else this_sucks (badluck);
else belongs to the inner
if , despite
formatting. Errors of this kind are also encountered in practice.
(“goto fail” in
iOS ). In gcc 6, a new warning was added
-Wmisleading -indentation . Unlike Python, in C it is more difficult for the compiler to determine whether the indentation is correct or not (you have to use heuristics).