Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何解决以下Python代码错误:IndentationError:应为缩进块_Python_Algorithm_Pycharm - Fatal编程技术网

如何解决以下Python代码错误:IndentationError:应为缩进块

如何解决以下Python代码错误:IndentationError:应为缩进块,python,algorithm,pycharm,Python,Algorithm,Pycharm,如何解决上述Python代码错误:缩进错误:预期为缩进块此代码旨在检查并返回数组值。编写Python代码时,应遵循基本缩进。。 提及 编写python代码时应遵循基本缩进。。 提及 Python使用缩进(每行开头的空格)来了解代码的组合。因此,范围(n)中i的缩进量需要大于def搜索的缩进量。另外,x=30不允许比arr=…更缩进。您应该学习python语法的基本知识(因此缩进,在python中是基本的)。就你而言def从第2列开始(应该从第1列开始),还有驾驶员代码:应该从第2列开始1@Aja

如何解决上述Python代码错误:缩进错误:预期为缩进块此代码旨在检查并返回数组值。

编写Python代码时,应遵循基本缩进。。 提及


编写python代码时应遵循基本缩进。。 提及


Python使用缩进(每行开头的空格)来了解代码的组合。因此,范围(n)中i的
缩进量需要大于
def搜索的缩进量。另外,
x=30
不允许比
arr=…
更缩进。您应该学习python语法的基本知识(因此缩进,在python中是基本的)。就你而言
def
从第2列开始(应该从第1列开始),还有驾驶员代码:应该从第2列开始1@Ajay我已经更新了您的代码并解决了缩进错误请参阅关于Python和indentation@UmairMubeen谢谢,我现在可以编译了。Python使用缩进(每行开头的空格)要知道什么代码一起使用。因此,范围(n)
中i的
缩进量需要大于
def搜索的缩进量。另外,
x=30
不允许比
arr=…
更缩进。您应该学习python语法的基本知识(因此缩进,在python中是基本的)。就你而言
def
从第2列开始(应该从第1列开始),还有驾驶员代码:应该从第2列开始1@Ajay我已经更新了您的代码并解决了缩进错误请参阅关于Python和indentation@UmairMubeen非常感谢。我现在可以编译了。这不应该是答案,因为你应该解释缩进错误发生的地方。这不应该是答案,因为你应该解释缩进错误发生的地方
# Python 3 implementation of the approach 

# Linearly search x in arr[]. If x is present 
# then return the index, otherwise return -1 
 
 def search(arr, n, x): 
 for i in range(n): 
     if arr[i] == x: 
        return i 
 return -1

# Driver Code 
arr = [1, 10, 30, 15] 
 x = 30
 n = len(arr) 
print(x, "is present at index",search(arr, n, x)) 
def search(arr, n, x): 
 for i in range(n): 
     if arr[i] == x: 
        return i 
 return -1

# Driver Code 
arr = [1, 10, 30, 15] 
x = 30
n = len(arr) 
print(x, "is present at index",search(arr, n, x))