0

好的,所以我正在创建一个循环:

def equ(par1,par2):
    con1=4/par1

    ready=False
    add=False

    if ready==True:
        if add==True:
            par2+=con1
            add=False
            print("true")
        elif add==False:
            par2-=con1
            add=True
            print("False")
    elif ready==False:
        par2=con1
    ready=True
    input()
    return par2

每次我运行程序时,它都没有做它应该做的事情。我注意到它不会改变为真。任何人都可以给我一些帮助吗?谢谢!:)

4

1 回答 1

1

First, you have no looping construct. You only have a linear flow of logic.

Second, ready==True will never be true, since it is explicitly set to False before that code block is ever hit.

If you're intending to reuse the boolean value ready, then you'd either want to preserve its state somewhere outside of the scope of the method - once you leave the method, it goes right back through and sets it to False again.

于 2013-04-14T21:05:06.840 回答