开发者

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

开发者 https://www.devze.com 2023-03-29 16:56 出处:网络
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:

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

精彩评论

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