Python Nested Function Set Outer Variable Cost