notice how this pattern avoids processing the sentinel item the first item is retrieved before the loop starts this is sometimes called the priming readas it gets the process started if the first item is the sentinelthe loop immediately terminates and no data is processed otherwisethe item is processed and the next one is read the loop test at the top ensures this next item is not the sentinel before processing it when the sentinel is reachedthe loop terminates we can apply the sentinel pattern to our number averaging problem the first step is to pick sentinel suppose we are using the program to average exam scores in that casewe can safely assume that no score will be below the user can enter negative number to signal the end of the data combining the sentinel loop with the two accumulators from the interactive loop version yields this program average py def main()sum count eval(input("enter number (negative to quit>")while > sum sum count count eval(input("enter number (negative to quit>")print("\nthe average of the numbers is"sum countmain( have changed the prompt so that the user knows how to signal the end of the data notice that the prompt is identical at the priming read and the bottom of the loop body now we have useful form of the program here it is in actionenter number (negative to quit> enter number (negative to quit> enter number (negative to quit> enter number (negative to quit> enter number (negative to quit> enter number (negative to quit>- the average of the numbers is this version provides the ease of use of the interactive loop without the hassle of having to type "yesall the time the sentinel loop is very handy pattern for solving all sorts of data processing problems it' another cliche that you should commit to memory this sentinel loop solution is quite goodbut there is still limitation the program can' be used to average set of numbers containing negative as well as positive values let' see if we can' generalize the program bit what we need is sentinel value that is distinct from any possible