Dec-11-2019, 08:20 PM
Hello, could someone let me know where am I going wrong with the below code please?
The programs is supposed to ask the user for a number input to make a grid based on that number and an error message if an incorrect number is entered. But at the moment it only generates a 5x5 grid regardless of what is input, if someone could point out my error and help me resolve this that would be greatly appreciate.
The programs is supposed to ask the user for a number input to make a grid based on that number and an error message if an incorrect number is entered. But at the moment it only generates a 5x5 grid regardless of what is input, if someone could point out my error and help me resolve this that would be greatly appreciate.
# Skeleton program for DrawGrid # define functions def GetGridSize(): validGrid = False while validGrid == False: print ("Please enter the size of the grid(max 20):") thisGridsize = int(input()) if (thisGridsize > 0) and (thisGridsize <=20): validGrid = True return thisGridsize def GetGridRow(aRowLength): # draws a single row using |_ for each square thisRow = '|_' * (aRowLength) # add closing | to row thisRow = thisRow + '|' return thisRow def DisplayGrid(aGridSize, aRow): # display top of grid using _ as top of each square print(' _' * aGridSize) # display rows of |_| for each row for rowCount in range(aGridSize): print(aRow) # main program gridSize = GetGridSize () rowToDraw = GetGridRow(5) DisplayGrid(5, rowToDraw)