GM logic for Python