How To Write A Function For A Global Variable In Python