we do not know how many vertices will be chosen the continuation condition is for pt to be in the rectangleso using the previously written function isinsidethe loop heading will be while isinside(ptrect)with this condition in mindlook for where to split to loop it needs to be after new pt is clicked (so it can be testedand before the next polygon is created (so it does not include the sentinel point by mistakein particularwith the sequence abovelook and see that the split could go before or after the poly undraw(line exercise moving undraw (page considers the case where the split goes before this line will proceed with the choice of splitting into python loop after the undraw line this makes the loop be while isinside(ptrect)vertices append(ptpoly polygon(verticespoly draw(winpt win getmouse(poly undraw(if you follow the total sequence of required steps above for making the concrete triangleyou see that this full sequence for the loop is only repeated twice the last time there is no poly undraw(step could redo the loop moving the undraw line to the topwhich caused different issues (exercise moving undraw (page belowinstead think how to make it work at the end of the final time through the loop there are several possible approaches you want the undraw line every time except for the last time hence it is statement you want sometimes and not others that suggests an if statement the times you want the undraw are when the loop will repeat again this is the same as the continuation condition for the loopand you have just read the next value for ptyou could just add condition in front of the last line of the loopif isinside(ptrect)poly undraw( find this option unaestheticit means duplicating the continuation test twice in every loop instead of avoiding the undraw as you exit the loopanother option in this case is to undo itjust redraw the polygon one final time beyond the loop this only needs to be done oncenot repeatedly in the loop then the repetitious lines collapse neatly into the loop if you look at the overall concrete sequence for the trianglenot all the lines are in the loop you must carefully include the lines both that come before the loop and those that come after the loop make sure these lines are not put in the loopbut before or afteras indicated by the concrete sequence in the example in the end the entire function isdef polyhere(rectwin)''draw polygon interactively in rectangle rectin graphwin win collect mouse clicks inside rect into the vertices of polygonand always draw the polygon created so far when click goes outside rectstop and return the final polygon the polygon ends up drawn the method draws and undraws rect ''rect setoutline("red"rect draw(winvertices list(pt win getmouse(while isinside(ptrect)vertices append(ptpoly polygon(verticespoly draw(winpt win getmouse(poly undraw(poly draw(win while statements