数字金字塔类型1、
n=int(input("数:"))
for i in range(1,n+1):
for j in range(1,i+1):
print(" %s"%j,end="")
if j==i:
print()
print()
for i in range(n,0,-1):
for j in range(i,0,-1):
print(" %s"%j,end="")
if j==1:
print()
print()
i=0
j=0
k=1
for i in range(2*(n-1),-1,-2):
for j in range(i,0,-1):
print(" ",end="")
for q in range(k,0,-1):
print(" %s"%q,end="")
if q==1:
print()
k+=1
k=n
print()
for i in range(1,2*n,2):
for j in range(i,1,-1):
print(" ",end="")
for q in range(1,k+1):
print(" %s"%q,end="")
print()
k-=1
数字金字塔类型2、
n=int(input("数:"))
k=1
m=0
for i in range((n-1)*4,-1,-4):
for j in range(0,i):
print(" ",end="")
for j in range(1,k+1):
print("%3s "%(2**m),end="")
m+=1
m-=2
for j in range(k,1,-1):
print("%3s "%(2**m),end="")
m-=1
if m>(k-1):
break
print()
m=0
k+=1