开发者

for-case loop evaluates second iteration twice and skips third iteration

So i have this code:

def Convert(ama,a):
    print ama,a

def run():
    z=0
    while z!=3:
        z+=1

        开发者_JS百科if z==1:
            n='e'
        if z==2:
            n='B'
        if z=='3':
            n='G'

        a='-----2-----5-6----7'
        Convert(a,n)
run()

The result:

-----2-----5-6----7 e
-----2-----5-6----7 B
-----2-----5-6----7 B

Although the result I expected was:

-----2-----5-6----7 e
-----2-----5-6----7 B
-----2-----5-6----7 G

Please help.


    if z=='3':

should be this

    if z==3:
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜