我把这个预定义的部分放在我的python代码中,代码的目的是获取最后2位数,并根据集群中的预定义逻辑将其放在集群列表中(索引作为列表[1]和集群中索引的变量(2)。 现在我的循环问题出现了缩进错误。
def find_min(matrix=[]):
i,j=0,0
min1=[1000,0,0]
while i <len(matrix):
while j <len(matrix):
if matrix[i][j] != 0:
if min1[0]>matrix[i][j]:
min1[0]=matrix[i][j]
min1[1]=i
min1[2]=j
j+=1
j=0
i+=1
return min1[1:]
def check_min(variable,list2=[]):
i=0
min=1000
list3=list2[:]
result=0
while i<len(list3):
if variable-list3[i]>0:
result=variable-list3[i]
list3[i]=result
else:
result=list3[i]-variable
list3[i]=result
i+=1
i=0
while i<len(list3):
if min>list3[i]:
min=list3[i]
i+=1
return min
def grouped(variable,cluster=[]):
cluster1=cluster[:]
k=0
list3=[]
index=0
while k<3:
index=k
if variable in cluster1[index]:
list3.append(1)
list3.append(cluster[index])
return list1
else:
continue
K+=1
return [0,-1]
list1=[10,11,30,40,70,80]
cluster=[[0,1][10,11],[2,3],[30,40],[],[]]
然后我想让这个循环工作,但它显示我的白痴错误!
w, h = len(list1), len(list1)
matrix = [[None for x in range(w)] for y in range(h)]
i,j,z=0,0,0
check=0
check2=0
k,e=0,0
flag1=0
index1,index2=0,0
index_i=0
index_j=0
index_cluster_i=0
index_cluster_j=0
temp1=[]
while i <len(list1):
index1=i
while j <len(list1):
index2=j
#if i is in a cluster already
temp1=grouped(index1,cluster)
index_i=temp1[0]
index_cluster_i=temp1[1]
#if j is in a cluster already
temp1=grouped(index2,cluster)
index_j=temp1[0]
index_cluster_j=temp1[1]
if(i>j):
matrix[i][j]=0
elif (index_i==1 and index_j==1):
matrix[i][j]=0
elif(index_i==1 and index_j==0):
matrix[i][j]=check_min(list1[j],cluster[index_cluster_i])
elif(index_i==0 and index_j==0):
if list1[i]>list1[j]:
matrix[i][j]=list1[i]-list1[j]
else:
matrix[i][j]=list1[j]-list1[i]
j+=1
i+=1
错误是:
unindent does not match any outer indentation level
答案 0 :(得分:0)
此错误是针对不正确的缩进对齐其声明下的每个块 像:
if i === True:
pass
else:
pass