Q:

Changing global integer variable from inside function scope

I want to have a global variable changed form inside a function.  The global variable is an integer.  I am getting an error when trying to do so.  This is a simplified version of what I am trying to do:
variable = 3

def test():

    b = 5
    if b > 0:
        variable -= 1
        print(variable)
    else:
        print('fail')

test()

Can anyone help me in finding a way to reduce the integer variable by 1 every time the function test runs? 

A:

When referring to a variable that's outside of a function that you don't pass in as a parameter, you must declare it as global before referencing it.  Add global variable to the beginning of your function and it should work.