How to fix NameError: global name 'function' is not defined in Python | DevErrors