UnboundLocalError: local variable ‘X’ referenced before assignment

This is very very common issue for beginners of Python.

Let me try tell you why:  my answer on Stack Overflow