Doubt in CNOTE

I submitted the solution for CNOTE and found that the solution was accepted when I tried to print the output outside the loop. Printing and breaking the loop works just as fine for one of the condition. What am I missing here ?

AC :
WA :

Ps : I’m a newbie to solving CP. Any improvements or suggestions for my code would be appreciated.