我一直觉得画这样的网格有点困难..
我需要一些帮助来获得一个特定的功能,可以为我绘制任何给定的数字网格
def grid(f, l):
print("{:10}".format("---+---" * f))
print("|{:12}|".format(" " * l))
print("|{:12}|".format(" " * l))
print("|{:12}|".format(" " * l))
print("{:10}".format("---+---" * f))
答案 0 :(得分:0)
那样的东西?
def grid(row, col):
"""version with string concatenation"""
sep = '\n' + '+---'*col + '+\n'
return sep + ('| '*col + '|' + sep)*row
print(grid(3,7))
结果:
+---+---+---+---+---+---+---+
| | | | | | | |
+---+---+---+---+---+---+---+
| | | | | | | |
+---+---+---+---+---+---+---+
| | | | | | | |
+---+---+---+---+---+---+---+
尽管使用列表理解与join
答案 1 :(得分:0)
{{1}}
答案 2 :(得分:0)
n=11
a=('+')*1 + (int(n/2)-1)*'-' + ('+')*1 + (int(n/2)-1)*'-' + ('+')*1
print(a)
for i in range(0,4):
b=('|')*1 + (int(n/2)-1)*' ' + ('|')*1 + (int(n/2)-1)*' ' + ('|')*1
print(b)
print(a)
for i in range(0,4):
b=('|')*1 + (int(n/2)-1)*' ' + ('|')*1 + (int(n/2)-1)*' ' + ('|')*1
print(b)
print(a)