You got your logic wrong at the function switch()
. See what happens in the beggining when switchvalue
is 1
def switch():
global switchvalue
if switchvalue == 1: # True
switchvalue = 0 # change it to 0
if switchvalue == 0: # Whoops, True again, because you switched it to 0 before
switchvalue = 1
As you can see you are changing switchvalue
to 0
then checking if it is 0
and then it gets changed back to 1
, in other words both if
statements are executed. You should instead use elif
or else
so that if one succeds the "if
loop" (metaphorically speaking) will break aka the other if
s will not be checked.
def switch():
global switchvalue
# IF one if succeds all the others will not be accounted
if switchvalue == 1:
switchvalue = 0
elif switchvalue == 0:
switchvalue = 1
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…