Pattern In Python Using Nested If And Or Statement