Stack Exchange
Python : "if" function does not work if the "if" statement have two conditions
Im working with python 3.6 and I wrote this:
zen = 1
zen2 = True
def test():
    if zen == 1 and zen2 == True:
        print ("hello")
        global zen2
        zen2 = False
    else:
        print ("hello 2")

test()

...and the output is NOTHING! NADA! No "hello" nor "hello 2", not even an error!
Even if I do this:
zen = 1
zen2 = True
def test():
    if zen == 1 :
        if zen2 == True:
            print ("hello")
            global zen2
            zen2 = False
        else:
            pass
    else:
        print ("hello 2")

test()

Still NOTHING! Why? 
Edit: I'm sorry everyone, before this I didn't notice the "else" does not have a colon,so for some they got a Syntax error, its probably fixed now,but it still outputs nothing
Edit 2: this is going to be embarrassing, as since i was using PyCharm and my other file is open (in the file, no function is executed), i accidentally ran the other file rather than the this "zen" file,so i got nothing because it. I actually got a SyntaxError from this "zen" file and this post really helped me with the problem even though I stated that was not the problem, and it also reminded myself to double check everything before doing anything, so yeah, thanks for anyone who helped me :)

Your code as it sits does not run.

Cannot reproduce. This prints "hello" after issuing a syntax warning.

Hello, @JazzHandy in order for us to help you we need an example that reproduces the behavior you are seeing. In this case when I run the code, the effect is just as you expect: https://ideone.com/eE50Lw

IIRC in Python2, the zen and zen2 uses in test() would be taken as global variables. In Python3, they're local variables unless you specifically make them global. You're using global, but too late and in the wrong place (after the condition). So the local zen and zen2 both get the default value of None.

I'm surprised there are a few different comments on whether this runs.  I get: SyntaxError: name 'zen2' is used prior to global declaration.  @JazzHandy this is definitely a scope issue though.

@Idlehands In QPython on my phone, I get the same message, but it's a SyntaxWarning, not an error, and it still prints. Odd.

@Idlehands - that might also depend on the Python version - I don't know for sure, but it makes sense that they might have added the check some time after adding global

Possible duplicate of Why does python behave this way with variables? Here's my previous answer on a similar scoping issue.

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)


I don't think this will do precisely what they want. zen2 = False suggests that they want subsequent calls to behave differently. Reassigning the zen2 parameter however won't have any effect.

Solution 1: Pass the arguments in the function.
Solution 2: Declare "zen" and "zen2" as global before declaration.

You have some logical errors.
You can not use zend2 before using global.
You should pass variables as arguments or declare them as global at first line of function.
