Solve any Number Pattern program in Python