Python Forum

Full Version: Indentation if/else problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I need assistance with writing if/else statements on Python 3.6. I am working on an iMac OS High Sierra (v 10.13.4). This is what I write:
>>> x = 10
>>> if x < 10:
print ('less than ten')
else:

SyntaxError: inconsistent use of tabs and spaces in indentation
>>>

After the print statement my cursor returns to under the 'p' of print. In order to get the curser under the 'i' in the if statement , I have to use back arrows and forward arrows to align them. I always get the SyntaxError message. I also noticed in the tutorial that after the print statement there are three ... under the >>> prompt to write the else or elif command. I have been working on a solution for hours but cannot come up with one. If anyone can help me I would surly appreciate it. Thank you. Rikk
you should always use 4 spaces per indentation level. using tab is allowed, but discouraged. In any case you should be consistent - always use only spaces or only tabs. In your case you mix the two, that's why you get that error: inconsistent use of tabs and spaces in indentation. Most editors would allow you to set an option to convert tabs to spaces automatically
the three dots ... are just to align your start position because in some of the other lines you have >>>

Finally, you are using interactive prompt. It's better to write your code as py file. In interactive mode you don't save your code for future use.
When ever I copy and paste what is in IDLE to this forum....it does not replicate accurately.

In any event what I described in words in my first post is what is actually happening. RIKK
Please, use proper tags when post code, traceback, output, etc.
See BBcode help for more info.

your problem is the mix of spaces and tabs, not wrong indentation. At least not yet...