2018-04-08 回答
# -*- coding:utf-8 -*-
"""
打印金字塔,随手写了个,肯定不是最优化的,供参考。
"""
def printgoldta(input):
l = [chr(i) for i in range(65,91)] ##大写字母a--z
ida = 65 #从a开始
idinput = ord(input)
num = idinput - ida + 1 ##a--输入的字符个数
print "a-->" + input + ":" + str(num)
tempresult =""
for c in range(0,num):
##左 [abcd]
for c1 in range(0,c):
tempresult = tempresult + l[c1]
## 中 [e]
tempresult = tempresult + l[c]
##右 [dcba]
for c2 in range(c-1,-1,-1):
tempresult = tempresult + l[c2]
##每行空格
for c3 in range(num-1-c): #
tempresult = " " + tempresult
##输出
print tempresult
##清空临时结果
tempresult = ""
#end for
#end def
printgoldta("e")
printgoldta("h")
###################
a-->e:5
a
aba
abcba
abcdcba
abcdedcba
a-->h:8
a
aba
abcba
abcdcba
abcdedcba
abcdefedcba
abcdefgfedcba
abcdefghgfedcba