# File: movingOn.py # Author: Dr. Gibson # Date: 10/15/2017 # Section: N/A # E-mail: k.gibson@umbc.edu # Description: # Build a two-dimensional list from scratch, populated # with a symbol chosen by the user. Then, print it back # out in grid form. def main(): width = int(input("Please enter a width: ")) height = int(input("Please enter a height: ")) symbol = input("Please pick a symbol to build with: ") ################################### # CREATE THE TWO-DIMENSIONAL LIST # start off with an empty game board gameBoard = [] # while the number of rows is less than the height while len(gameBoard) < height: # start building a brand new row # (we can't use the same one because of mutability!) boardRow = [] # while the length of the row is less than width while len(boardRow) < width: boardRow.append(symbol) # at this point, we have a complete row built gameBoard.append(boardRow) ################################## # PRINT THE TWO-DIMENSIONAL LIST row = 0 # len(gameBoard) is the number of interior lists inside gameBoard while row < len(gameBoard): col = 0 # len(gameBoard[row] is the length of THIS interior list while col < len(gameBoard[row]): print( gameBoard[row][col], end=" ") col += 1 # a complete row has been printed, now end the line print() row += 1 main()