题目:
小明希望用星号拼凑,打印出一个大X,他要求能够控制笔画的宽度和整个字的高度。
为了便于比对空格,所有的空白位置都以句点符来代替。
要求输入两个整数m n,表示笔的宽度,X的高度。用空格分开(0<m<n, 3<n<1000, 保证n是奇数)
要求输出一个大X
例如,用户输入:
3 9
程序应该输出:
再例如,用户输入:
4 21
程序应该输出
代码实现:
#一个依存于bug运行的代码
n,row=map(int,input().split(' '))
s=[]
line=n+row-1
count_left=count_right=0
count=line-2*n
#打印上半部分
while count>0:
for i in range(row):#BUG,row无用,写几都可
x='.'*count_left+'*'*n+'.'*count+'*'*n+'.'*count_right
print(x)
s.append(x)
count_left+=1
count_right+=1
count-=2
break
temp=line-count_left-count_right
#打印中间*合起来的部分
for i in range(2):
#BUG,这2我也不知道啥,当初随便填的,填几都可,反正跑起来了,while temp==n不行我才用for的
x='.'*count_left+'*'*temp+'.'*count_right
print(x)
s.append(x)
count_left+=1
count_right+=1
temp-=2
if temp==n:
break
k=int((line-n)/2)
print('.'*k+'*'*n+'.'*k)#打印中间一行
s.reverse()#翻转数组打印下面的部分
for i in s:
print(i)