SUGGESTED_SIZE = 10 # Author: James Tam # Version: May 27, 2020 # args(integer,integer) # Creates a 2D list with num rows = 1st argument, num columns = 2nd argument # return (reference to the list) def createList(maxRows,maxColumns): #Declare variables for function aList = [] r = -1 c = -1 for r in range(0,maxRows,1): aList.append([]) #Create a reference to empty 1D list (row) #Each time through the inner loop a new row is created, each element is a star #Num stars = maxColumns for c in range(0,maxColumns,1): aList[r].append("*") #Add a new element onto the end of the 1List return(aList) # args(reference to a list,integer,integer) # displays each element of list with a row on it's own line # return(nothing) def display(aList,maxRows,maxColumns): #Declare variables for function r = -1 c = -1 r = 0 # Each iteration of the outter loop accesses another row while (r < maxRows): c = 0 # Each iteration of the inner loop accesses another element along that row while (c < maxColumns): #Display each element along a row on the same line print("%s" %(aList[r][c]),end="") c = c + 1 print("") #After each row printed add a new line (EOL) r = r + 1 # args(none) # Gets the number of rows and columns (list size). It doesn't error check the input but # does suggest the max size at the prompt. # return(integer,integer) def getSize(): #Declare variables for function maxRows = -1 maxColumns = -1 print("Enter max. # of rows, suggested max=%d: " %(SUGGESTED_SIZE), end="") maxRows = int(input("")) print("Enter max. # of columns, suggested max=%d: " %(SUGGESTED_SIZE), end="") maxColumns = int(input("")) return(maxRows,maxColumns) #Starting execution point for the program def start(): #Declare variables local to starty aList = [] maxRows = -1 maxColumns = -1 maxRows,maxColumns = getSize() aList = createList(maxRows,maxColumns) display(aList,maxRows,maxColumns) start()