Can you please tell me why the parent-child relationship needs to be appended inside the for loop to get the expected output. I am not understanding scope in Python