I wrote a simple script which increments a integer, but it is not working and i got an error.
my script :
x = 1
def inc():
    x +=1
    print(x)
if __name__ == "__main__""" :
    inc()
when i run this script i got this :
palash@ash:~/PycharmProjects/src$ python tt.py
Traceback (most recent call last):
  File "tt.py", line 7, in <module>
    inc()
  File "tt.py", line 3, in inc
    x +=1
UnboundLocalError: local variable 'x' referenced before assignment
palash@ash:~/PycharmProjects/src$
my python version : Python 3.6.1 :: Anaconda custom (32-bit)
and I'm running on Ubuntu 17.04 32bit
I can't understand what is happening. Help me please
Edit: And can anybody define what is UnboundLocalError?
And Why  "__main__"""is working ?
 
    