Pattern In Python Using Nested If Function