Pattern In Python Using Nested If