Python Nested Function Set Outer Variable In Math