字母排列成棱形

时间:2021-07-14
本文章向大家介绍字母排列成棱形,主要包括字母排列成棱形使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

效果如下:

def my_print(char):
    list = ['A','B','C','D','E','F']
    rows = (ord(char)-63)
    rows_str = []
    for row in range(0,rows):
        str = ""
        for i in range(0,row):
            str += list[i]
        for i in range(row-2,-1,-1):
            str += list[i]
        rows_str.append(str)
    for row in range(rows-2,-1,-1):
        str = ""
        for i in range(0, row):
            str += list[i]
        for i in range(row - 2, -1, -1):
            str += list[i]
        rows_str.append(str)
    for str in rows_str:
        print("| %s |"%str.center(11))
my_print("D")
View Code
>>> help(str.center)
Help on method_descriptor:

center(self, width, fillchar=' ', /)
Return a centered string of length width.

Padding is done using the specified fill character (default is a space).

>>>
>>> help(ord)
Help on built-in function ord in module builtins:

ord(c, /)
    Return the Unicode code point for a one-character string.

>>> 

原文地址:https://www.cnblogs.com/blogzyq/p/15010540.html