-4

I'm a beginner in python and I'm facing an error :IndentationError: expected an indented block"

for the following simple code

num = 3
if num >= 0:
    print("positive number")
else:
    print("Negtive number")

I need to fix this in python 3.7

  • If that is the entirety of your code, the only issue I can see is that your `print` statements are indented by 5 spaces, not 4 – Andrew Dec 29 '18 at 10:07
  • I sometimes ran into this issue with a text editor I was using. The solution for me back then was to hit backspace on the indentented lines until they were pulled up to the previous line and the hit enter again. Maybe you have the same problem. Does your texteditor specify a line for the error? Code works fine for me when I copy and paste it – Dominique Paul Dec 29 '18 at 10:10
  • [Read This](https://stackoverflow.com/questions/1024435/how-to-fix-python-indentation) – Rohit-Pandey Dec 29 '18 at 10:15
  • 5
    The code you have posted does not produce the error you are describing. – khelwood Dec 29 '18 at 10:19

3 Answers3

1

Another approach can be:

1) Select the entire content of the file "(Ctrl + A)".

2) Then find an option like "Converting Indentation to Spaces" in your Text Editor.

0

press tab in your text editor instead of using spaces if you are using spaces

RedPython
  • 48
  • 5
0

Python doesn't use braces. It uses indentation to determine which block of code comes under which.

I'd recommend using tabs over spaces. Just backspace all the spaces behind the print statement and then use tab to indent it.

therochvoices
  • 91
  • 1
  • 9