Programiz Python Complex Problem