python - 在 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)
解决方案
它现在正在工作!希望有些人觉得这有帮助:)
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()
推荐阅读
- php - Codeigniter/CSS PDF 打印输出对齐 PDF 位置
- java - 通过 Neo4j 程序实现只读算法的多线程
- codeigniter-3 - 选项类型编号中的 jQuery 数据输入验证最小值和最大值
- latex - gnuplot epslatex 无法重新绘制
- matlab - 如何绘制不等式方程
- javascript - 将wav文件加载到内存时控制台中的菱形问号,如何重新编码为二进制?
- opendaylight - Opendaylight 从构建器转换为 JSON
- css - 如何将字体从 CSS 外部资源转换为 JSON
- swift - Swift 类型下标
- laravel - 电子邮件验证。由于目标机器主动拒绝,无法建立连接