各位大神,最近刚开始学python,感觉挺好用的,然后看到网上有家公司要求用php制作一个小程序,就用python做了一个,要求是让一个门上打几个孔,然后根据一条相距为32的倍数的规则,判断是用多把刀钻孔还是一把刀钻孔。里面有什么不规范的、错的地方请指点一下,小弟统统虚心接收:)
==============================================================
# coding=gbk
print "WELCOME"
w = raw_input("Input the number:")
N={}
for i in range(0,int(w)):
print "NO %s"%(i+1)
L= raw_input("Input the L:")
X= raw_input("Input the X:")
Y= raw_input("Input the Y:")
N[i]=[L,X,Y]
for j in range(len(N)-1,0,-1):
for u in range(0,j):
c = int(N[u+1][1])-int(N[u][1])
if c < 0:
b = N[u]
N[u] = N[u+1]
N[u+1] = b
for k in range(len(N)-1,0,-1):
for l in range(0,k):
if int(N[u+1][1]) == int(N[u][1]):
v = int(N[u+1][2])-int(N[u][2])
if v < 0:
b = N[u]
N[u] = N[u+1]
N[u+1] = b
O = N
print "The Old O is : %s"%O
while O<>{}:
A={}
A[0]=O[0]
m=0
for z in range(1,len(O)):
Xsame = True
Ysame = True
CHA = 0
g=1
PAN = ((A[0][1]==O[z][1]) and (A[0][2]==O[z][2])) or ((A[0][1] <> O[z][1]) and (A[0][2] <> O[z][2]))
XCHA=abs(int(A[0][1])-int(O[z][1]))
YCHA=abs(int(A[0][2])-int(O[z][2]))
cha=((XCHA==0) and (((YCHA%32)<>0) or ((YCHA//32) > 4))) or ((YCHA==0) and (((XCHA%32)<>0) or ((XCHA//32) > 4)))
Pan=(PAN or cha)
if Pan == True:
""
elif A[0][1] == O[z][1]:
Xsame = True
Ysame = False
CHA0 = abs(int(A[0][2])-int(O[z][2]))
if ((CHA0%32==0) and ((CHA0//32) <= 4)):
if z==1:
A[z]=O[z]
O[z]=[0,1,2]
m=m+1
elif m<>0:
pan=(((A[1][1]==O[z][1]) and (A[1][2]==O[z][2])) or ((A[1][1] <> O[z][1]) and (A[1][2] <> O[z][2])))
if pan==False:
A[z]=O[z]
O[z]=[0,1,2]
else:
""
break
else:
A[z]=O[z]
O[z]=[0,1,2]
else:
""
elif A[0][2] == O[z][2]:
Xsame = False
Ysame = True
CHA0 = abs(int(A[0][1])-int(O[z][1]))
if ((CHA0%32==0) and ((CHA0//32) <= 4)):
if z==1:
A[z]=O[z]
O[z]=[0,1,2]
m=m+1
elif m<>0:
pan=((A[1][1]==O[z][1]) and (A[1][2]==O[z][2])) or ((A[1][1] <> O[z][1]) and (A[1][2] <> O[z][2]))
if pan==False:
A[z]=O[z]
O[z]=[0,1,2]
else:
print A
CHA1 = abs(int(A[1][2])-int(A[0][2]))
if (CHA0//32)<(CHA1//32):
P={}
K={}
f=len(O)
for s in range(1,len(A.values())):
O[s+f-1]=A.values()[s]
P[0]=A[0]
P[1]=O[z]
O[z]=[0,1,2]
A=P
g=0
for e in range(1,len(O)):
K[e-1]=O[e]
O=K
for j in range(len(O)-1,0,-1):
for u in range(0,j):
c = int(O[u+1][1])-int(O[u][1])
if c < 0:
b = O[u]
O[u] = O[u+1]
O[u+1] = b
for k in range(len(O)-1,0,-1):
for l in range(0,k):
if int(O[u+1][1]) == int(O[u][1]):
v = int(O[u+1][2])-int(O[u][2])
if v < 0:
b = O[u]
O[u] = O[u+1]
O[u+1] = b
else:
""
else:
A[z]=O[z]
O[z]=[0,1,2]
else:
""
else:
""
K=O.values()
P={}
j=0
i=0
for z in range(0,len(K)-1):
d = (K[z+1]==[0,1,2])
if d==True:
j=j+z
else:
P[i]=K[z+1]
i=i+1
K[z+1]=[0,1,2]
K=P
O=K
print "刀规格 :[直径,X坐标,Y坐标] : %s"%(A.values())
raw_input()