Python输出阶梯或金字塔图案

来源:互联网 发布:淘宝收货时间是多久 编辑:程序博客网 时间:2024/06/04 19:32

 1.输出:
$
$$
$$$
$$$$

height = int(input("请输入行数:\n"))for i in range(height):    for j in range(i+1):        print("$ ", end='')    print("\n")

2.获得一个大写字母(例如F),输出类似内容
F
FE
FED
FEDC
FEDCB
FEDCBA

theStr=input("please input the letter:\n")theCode=ord(theStr)for i in range(1,theCode-65+2):    for j in range(theCode,theCode-i,-1):        print(chr(j),end='')    print("\n")

3.获得一个大写字母(例如F),输出类似内容:
           A
         ABA
       ABCBA
    ABCDCBA
  ABCDEDCBA
ABCDEFEDCBA

theStr = input('please input the letter:\n')theCode = ord(theStr)i = 65while 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")





原创粉丝点击