How to fix IndentationError: “expected an indented block”?

后端 未结 2 1842
南方客
南方客 2021-01-29 09:50

I get an error

IndentationError: expected an indented block

in line line 3

answer = subprocess.check_output([\'/home/dir/         


        
2条回答
  •  自闭症患者
    2021-01-29 10:22

    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)
    

提交回复
热议问题