首页 > 解决方案 > 在 Python 中使用用户的网格大小的表

问题描述

使用网格大小绘制表格的程序。提示用户输入尺寸 - 我不知道为什么会出现语法错误

def getgridsize():
  aRowLength=int(input("Enter grid size, max 20:\n"))
  while aRowLength<=0 and aRowLength>20:
    aRowLength=int(input("Please enter the size of the gird, max 20: \n")
  
  GetGridRow(aRowLength)
  
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):
  aGridSize=int(input("Enter the grid size:"))
    # 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)

def main():
  getgridsize()
  DisplayGrid(aGridSize, rowToDraw)

标签: python

解决方案


它现在正在工作!希望有些人觉得这有帮助:)

  def getgridsize():
  aRowLength=int(input("Enter grid size, max 20:\n"))
  while aRowLength<=0 and aRowLength>20:
    aRowLength=int(input("Please enter the size of the gird, max 20: \n"))
  if aRowLength>0 and aRowLength<=20:
    GetGridRow(aRowLength)
  
def GetGridRow(aRowLength):
    # draws a single row using |_ for each square
  thisRow = '|_' * (aRowLength)
    # add closing | to row
  thisRow = thisRow + '|'
  
  DisplayGrid(thisRow)

def DisplayGrid(thisRow):
  aGridSize=int(input("Enter the grid size:"))
    # display top of grid using _ as top of each square
  print(' _' * aGridSize)
    # display rows of |_| for each row
  for rowCount in range(aGridSize):
    print(thisRow)

def main():
  getgridsize()

推荐阅读