for (rectanglechoicein choicepairsif isinside(pointrectangle)return choice return default note that the else part in choosebutton py corresponds to the statement after the loop above if execution gets past the loopthen none of the conditions tested in the loop was true with appropriate parametersthe looping function is complete replacement for the original if-elif statementthe replacement has further advantages there can be an arbitrarily long list of pairsand the exact same code works this code is clearer and easier to readsince there is no need to read through long sequence of similar if-elif clauses the names of the rectangles in the tuples in the list are never referred to they are unnecessary here only list needs to be specified that could be useful earlier in the program are individual names for the rectangles needed earliernothe program only needs to end up with the pairs of the form (rectanglecolorin list the statements in the original programbelowhave similar form which will allow them to be rewrittenredbutton makecoloredrect(point( ) 'red'winyellowbutton makecoloredrect(point( ) 'yellow'winbluebutton makecoloredrect(point( ) 'blue'winas stated earlierwe could use the statements above and then make list of pairs with the statement choicepairs [(redbuttton'red')(yellowbutton'yellow')(bluebutton'blue')now will look at an alternative that would be particularly useful if there were considerably more buttons and colors all the assignment statements with makecolorrect have the same formatbut differing data for several parameters use that fact in the alternate codechoicepairs list(buttonsetup [( 'red')( 'yellow')( 'blue')for (xycolorin buttonsetupbutton makecoloredrect(point(xy) colorwinchoicepairs append((buttoncolor) extract the changing data from the creation of the rectangles into listbuttonsetup since more than one data items are different for each of the original linesthe list contains tuple of data from each of the original lines then loop through this list and not only create the rectangles for each colorbut also accumulates the (rectanglecolorpairs for the list choicepairs note the double parentheses in the last line of the code the outer ones are for the method call the inner ones create single tuple as the parameter assuming do not need the original individual names of the rectanglesthis code with the loop will completely substitute for the previous code with its separate lines with the separate named variables and the recurring formats this code has advantages similar to those listed above for the getchoice code now look at what this new code means for the interactive part of the program the interactive code directly reduces to msg text(point(win getwidth()/ ),'click to choose house color 'msg draw(wincolor getchoice(colorpairs'white'win more on flow of control