V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
jimmyrui
V2EX  ›  问与答

python 语言学习

  •  
  •   jimmyrui · 2014-06-27 16:55:38 +08:00 · 3012 次点击
    这是一个创建于 3838 天前的主题,其中的信息可能已经有所发展或是发生改变。
    各位大神,最近刚开始学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()
    3 条回复    2014-06-27 20:34:26 +08:00
    cbsw
        1
    cbsw  
       2014-06-27 18:41:19 +08:00
    提几个建议:
    1. 把代码放到 gist 上去,然后把链接贴过来,V2EX 会自动嵌入 gist
    2. 不要试图让别人帮你实现业务逻辑,即请别人指正业务上的错误,除非是算法或数据结构之类的,代码不规范倒是会有热心人帮你指出
    heliar
        2
    heliar  
       2014-06-27 19:15:17 +08:00 via iPhone
    …话说注释也要写一下吧…
    holy_sin
        3
    holy_sin  
       2014-06-27 20:34:26 +08:00
    @cbsw nice,下次我也这么搞
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2352 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 15:52 · PVG 23:52 · LAX 07:52 · JFK 10:52
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.