Semaine 4, jour 5
This commit is contained in:
18
Semaine_04/Gauvain_BOICHE/exo_03.py
Normal file
18
Semaine_04/Gauvain_BOICHE/exo_03.py
Normal file
@@ -0,0 +1,18 @@
|
||||
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
|
||||
Reference in New Issue
Block a user