如何指定默认值?
r=int(input('Number of rows?: '))
c=int(input('Number of Columns?: '))
w=int(input('Width of a column'))
h=int(input('Height of a row'))
row= (('+')+ w*('-')+('+'))* (c)
width= (('-') * w)*c
col=(('+')+ w*('-')+('+'))
height=(('|')+ w * (' ')+ ('|'))* c
c=square brackets with zero in it
for i in range(r):
print(row)
print(height)
c.append(col)
print(c* square brackets having zero)
但它没有工作...... [问题显示在上传的下图中] http://i.stack.imgur.com/JLQ8i.jpg
答案 0 :(得分:1)
这是我对你要做的事情的最好猜测:
r = int(input('Number of rows?: ') or 4)
c = int(input('Number of Columns?: ') or 4)
w = int(input('Width of a column') or 4)
h = int(input('Height of a row') or 4)
row = (('+') + w * ('-')) * (c) + '+'
width= (('-') * w) * c
col = (('+') + w * ('-') + ('+'))
height = (('|') + w * (' ')) * c + '|'
#c=square brackets with zero in it
for i in range(r):
print(row)
for j in range(h):
print(height)
print(row)
#c.append(col)
#print(c* square brackets having zero)
示例运行:
Number of rows?: 3
Number of Columns?: 4
Width of a column5
Height of a row6
+-----+-----+-----+-----+
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
+-----+-----+-----+-----+
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
+-----+-----+-----+-----+
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
+-----+-----+-----+-----+
也许您可以提供一些示例输出,并阐明您尝试使用c
进行的操作。