for in range( - )print(iprint('blastoff!'countdown interactive while loops the earlier examples of while loops were chosen for their simplicity obviously they could have been rewritten with range function calls now lets try more interesting example suppose you want to let user enter sequence of lines of textand want to remember each line in list this could easily be done with simple repeat loop if you knew the number of lines to enter for examplein readlines pythe user is prompted for the exact number of lines to be enteredlines list( int(input('how many lines do you want to enter')for in range( )line input('next line'lines append(lineprint('your lines were:'for line in linesprint(linecheck now the user may want to enter bunch of lines and not count them all ahead of time this means the number of repetitions would not be known ahead of time while loop is appropriate here there is still the question of how to test whether the user wants to continue an obvious but verbose way to do this is to ask before every line if the user wants to continueas shown below and in the example file readlines py read it and then run itlines list(testanswer input('press if you want to enter more lines'while testanswer =' 'line input('next line'lines append(linetestanswer input('press if you want to enter more lines'print('your lines were:'for line in linesprint(linesee the two statements setting testanswerone before the while loop and one at the bottom of the loop body notethe data must be initialized before the loopin order for the first test of the while condition to work also the test must work when you loop back from the end of the loop body this means the data for the test must also be set up second timein the loop body (commonly as the action in the last line of the loopit is easy to forget the second timethe readlines py code worksbut it may be more annoying than counting aheadtwo lines must be entered for every one you actually wanta practical alternative is to use sentinela piece of data that would not make sense in the regular sequenceand which is used to indicate the end of the input you could agree to use the line doneeven simplerif you assume all the real lines of data will actually have some text on themuse an empty line as sentinel (if you think about itthe python shell uses this approach when you enter statement with an indented body this way you only need to enter one extra (very simplelineno matter how many lines of real data you have what should the while condition be nowsince the sentinel is an empty lineyou might think line =''but that is the termination conditionnot the continuation conditionyou need the opposite condition to negate condition in pythonyou may use notlike in english more on flow of control