-1

I get an error

IndentationError: expected an indented block

in line line 3

answer = subprocess.check_output(['/home/dir/final/3.sh'])

My code is:

import subprocess
while True:
answer = subprocess.check_output(['/home/dir/final/3.sh'])
final = int(answer) // int('1048576')
print final
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
marker
  • 11
  • 1
  • One of the many great things about Python is that its' error and failure handling is fantastic. This means that the errors mean what they say and don't mean what they don't say. The following is a great resource for searching when you get errors: https://docs.python.org/3.5/library/exceptions.html – Douglas Dec 13 '16 at 23:17
  • Was the code copied from the a web page? – Peter Mortensen Jun 08 '23 at 08:09
  • How is this not a duplicate? It was 8 years after the launch of Stack Overflow. – Peter Mortensen Jun 08 '23 at 08:09
  • Candidate (see also its [linked questions](https://stackoverflow.com/questions/linked/45621722)): *[I'm getting an IndentationError. How do I fix it?](https://stackoverflow.com/questions/45621722/im-getting-an-indentationerror-how-do-i-fix-it)* – Peter Mortensen Jun 08 '23 at 08:59

2 Answers2

2

In documentation terminology, indentation means the space from margin to the begin of characters in a line.

Python uses indentation. In your code, While is a condition, all the block of code to be executed for true, must start at same position from the margin, must be farther away from margin than that of the condition.

I too faced this error.

Example:

if __name__ == '__main__':
    a = int(input())
    b = int(input())
    if a>=1 and a<=10000000000 and b>=1 and b<=10000000000:
    print(a+b)
    print(a-b)
    print(a*b)

will throw "IndentationError: expected an indented block (solution.py, line 5)"

Fix:

if __name__ == '__main__':
    a = int(input())
    b = int(input())
if a>=1 and a<=10000000000 and b>=1 and b<=10000000000:
    print(a+b)
    print(a-b)
    print(a*b)
Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Surendra
  • 25
  • 8
1

Python requires indentation to indicate code that is conditional under for loops, while loops, if and else statements, etc. Generally, this is code that runs contingent on logic before a colon.

Most coders use four spaces for indentation.

Tabs are a bad idea because they may create different amount if spacing in different editors. They're also potentially confusing if you mix tabbed indentation with spaced indentation. If you're using an IDE like Eclipse or Eric, you can configure how many spaces the IDE will insert when you press tab.

I think your code should be:

import subprocess 

while True: 
    answer = subprocess.check_output(['/home/dir/final/3.sh']) 
final = int(answer) // int('1048576')
print final
trinkner
  • 374
  • 4
  • 15