# Author: James Tam # Version: May 24, 2024 # * Added more debugging messages. # * Modifier the implementation of the hard coded list to better # contrast with 'aGrid' # Version: November 21, 2022 # Learning objective: # * In the context of the append method knowing exactly what 'level' # (reference, whole list, row, element in a list (at a row/column) # that an instruction refers to. aGrid = [] noRows = int(input("Number rows: ")) noColumns = int(input("Number columns: ")) #Create list for r in range (0,noRows,1): aGrid.append ([]) for c in range (0,noColumns,1): aGrid.append("*") #print(aGrid) #print("# elements", len(aGrid)) #print("type of the list", type(aGrid)) #print(len(aGrid)) #print(len(aGrid[0])) for r in range (0,noRows,1): aGrid.append ([]) for c in range (0,noColumns,1): print(aGrid[r][c], end="") print() """ #Hard-coded 2D list anotherGrid = [[1,2,3], [3,2,1]] print("anotherGrid: type of information for 2nd element (1D list or string)", type(anotherGrid[1])) print("aGrid: type of information for 2nd element (1D list or string)", type(anotherGrid[1])) #Display list for r in range (0,2,1): for c in range (0,3,1): print(anotherGrid[r][c], end="") print() print("# elements", len(anotherGrid)) print("type of the list", type(anotherGrid)) print(len(anotherGrid)) print(len(anotherGrid[0])) """