[Solved] Python : “if” function does not work if the “if” statement have two conditions


I assume this is what you wanted to achive:

def test(zen, zen2):
    if zen == 1 and zen2 == True:
        print ("hello")
        zen2 = False
    else:
        print ("hello 2")

test(1, True)

As some comments suggested, if one tries to run your code, it returns following (on linux GCC 4.8.2/Python 3.6.1):

SyntaxError: name 'zen2' is used prior to global declaration

In case you want to change the value printed after the first evaluation of the condition, rewrite it like this:

def test(zen, zen2):
    if zen == 1 and zen2 == True:
        print ("hello")
        zen2 = False
        test(zen, zen2)
    else:
        print ("hello 2")

test(1, True)

1

solved Python : “if” function does not work if the “if” statement have two conditions