编写Python程序输出正金字塔

2025-05-11 16:27:28
推荐回答(1个)
回答1:

theStr = input('please input the letter:F\n')  #请输入大写F
theCode = ord(theStr)  
i = 65  
while i <= theCode:  
    for j in range(theCode-i,0,-1):  
        print(" ",end='')  
        #输出相应的空格  
    for i_temp in range(65, i):  
        print(chr(i_temp), end='')  
        #正向输出字母  
    for i_temp_temp in range(i, 64, -1):  
        print(chr(i_temp_temp), end='')  
        #反向补齐输出字母  
    i+=1  
    print("\n")  
#如果成功,请再输入小写f试试,效果更好!