How To Write Nested Function In Python