Algorithm For Order Of Operation In Python