python怎样打印字母金字塔
可使用嵌套循环来打印字母金字塔,下面是一个示例代码:
def print_pyramid(rows):
for i in range(rows):
print(' ' * (rows - i - 1) + '*' * (2 * i + 1))
rows = 5
print_pyramid(rows)
运行以上代码会打印一个5行的字母金字塔,结果以下:
*
***
*****
*******
*********
TOP