python 语言学习

2014-06-27 16:55:38 +08:00
 jimmyrui
各位大神,最近刚开始学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()
3012 次点击
所在节点    问与答
3 条回复
cbsw
2014-06-27 18:41:19 +08:00
提几个建议:
1. 把代码放到 gist 上去,然后把链接贴过来,V2EX 会自动嵌入 gist
2. 不要试图让别人帮你实现业务逻辑,即请别人指正业务上的错误,除非是算法或数据结构之类的,代码不规范倒是会有热心人帮你指出
heliar
2014-06-27 19:15:17 +08:00
…话说注释也要写一下吧…
holy_sin
2014-06-27 20:34:26 +08:00
@cbsw nice,下次我也这么搞

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/119854

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX