Pattern In Python Using Nested Ifs