如何修复IndentationError:“预期缩进的块"? [英] How to fix IndentationError: "expected an indented block"?

查看:62
本文介绍了如何修复IndentationError:“预期缩进的块"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到一个错误

IndentationError:预期为缩进的块

IndentationError: expected an indented block

第3行

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

我的代码是:

import subprocess
while True:
answer = subprocess.check_output(['/home/dir/final/3.sh'])
final = int(answer) // int('1048576')
print final

推荐答案

在文档术语中,缩进表示从空白处到行中字符开头的距离.

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

Python使用缩进.在您的代码中,虽然这是一个条件,但要执行为true的所有代码块必须从空白处开始在同一位置,并且必须比该条件离空白处更远.

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.

我也遇到了这个错误.

示例:

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)

将抛出"IndentationError:预期为缩进的块(solution.py,第5行)"

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

修复:

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)

这篇关于如何修复IndentationError:“预期缩进的块"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆