19 lines
508 B
Python
19 lines
508 B
Python
def gen_pyramid(num: int) -> list[str]:
|
|
"""
|
|
A partir d'un entier, renvoie sous forme de tableau une
|
|
pyramide composée d'autant d'étages avec le caractère *
|
|
"""
|
|
if num == 0:
|
|
return ["Merci d'utiliser un entier non nul."]
|
|
if num < 0:
|
|
num = +abs(num)
|
|
|
|
pyramid = []
|
|
|
|
for n in range(num):
|
|
white_spaces = ' ' * (num - n - 1)
|
|
bloc_spaces = '*' * (2 * n + 1)
|
|
pyramid.append(f"{white_spaces}{bloc_spaces}{white_spaces}")
|
|
|
|
return pyramid
|