原题目要求:
实验楼楼赛打印围城
用PHP
Python实现:
import sys
parameter = sys.argv[1:]
num = parameter.__len__()
if num < 2:
print('Parameter Error')
exit(1)
n = (num-1) * 2 + 1
second = list(range(1,num))[::-1]
def echo(N):
a=N-1
s=str()
for i in range(a):
s = s + parameter[i]
c = parameter[a]*(n-2*a)
return s + c + s[::-1] + "\n"
def run():
string = str()
for i in range(num):
string = string + echo(i+1)
for i in second:
string = string + echo(i)
print(string)
run()
效果:
image.png
image.png
网友评论