python打印技巧
def jar(b):
if not isinstance(b,int) or not b > 0:
print('inaccurate')
return None
vv=len(str(b))+1
for i in range(b):
for j in range(b-1,-1,-1):
if j <= i:
print('{:<{}}'.format(j+1,vv),end='')
else:
print(' '*vv,end='')
print()
for i in range(b-1,-1,-1):
for j in range(b-1,-1,-1):
if j <= i:
print('{:<{}}'.format(j+1,vv),end='')
else:
print(' '*vv,end='')
print()
def hum(b):
if not isinstance(b,(int,)) or not b > 0:
print('inaccurate')
tail=' '.join([str(b-v) for v in range(b)])
width=len(tail)
for p in range(b-1):
print('{:>{}}'.format(' '.join([str(m+1) for m in range(p,-1,-1)]),width))
print(tail)
head=' '.join([str(b-v) for v in range(b)])
print(head)
for p in range(len(head)):
if head[p]==' ':
print(' '*p,head[p+1:])
hum(12)