''' Purpose: another take on nested loops ''' # make random module resources available import random # create a table where the element of the rth row in column c is a random # value from the range( 10, 100 ) # set dimensions of a table reply = input( "Enter number of rows: " ) rows = int( reply ) reply = input( "Enter number of columns: " ) columns = int( reply ) # ask for and set the and seed for the random number generation reply = input( "Enter a word: " ) word = reply.strip() random.seed( word ) print() #### show that a simple range-based loop # print the row indices of the table for r in range( 0, rows ) : print( "row:", r ) print() #### show that a nested range-based loop # print the individual row and column indices into the table for r in range( 0, rows ) : for c in range( 0, columns ) : print( "row:", r, "column:", c ) print() print() # create the table table = [] # create an empty table. it is our row # accumulator for r in range( 0, rows ) : # build the table row by row # need to start a new row for the table row = [] # row is set to be a fresh accumulator # for each column c in the new row, its value is r + c for c in range( 0, columns ) : value = random.randrange( 10, 100 ) row.append( value ) # got a row, let's add it to the table table.append( row ) # let's print the row to see what we got print( row ) print() print( table )