题目:
首先,我们先询问边长
n=int(input())
然后,新建2个变量,1个为x,1个为-
b='-'
b1='x'
先输出第一行
在for循环,最后输出最后一行。
代码如下:
n=int(input())
c=n
b='x'
b1='-'
print('|',b1*(c-2),'|')
for i in range(1,n-1):
if i!=(c+1)//2:
print('|',b*(c-2),'|')
if i==(c+1)//2:
print('|',b1*(c-2),'|')
print('|', b1*(c-2), '|')
如有不对,请私信博主