efrei/algorithmique/recursivite/pyramide.py

22 lines
475 B
Python
Raw Normal View History

2021-09-21 09:37:00 +02:00
#!/usr/bin/env python
"""Dessine une pyramide d'étoiles selon un entier N donné, N étant impair"""
def main() -> None:
for line in reversed(creer_pyramide(9, [])):
print(line)
def creer_pyramide(N: int, pyramide: list[str]) -> list[str]:
if N == 0:
return pyramide
else:
nombre_etoiles = 2 * N - 1
pyramide.append("*" * nombre_etoiles)
return creer_pyramide(N - 1, pyramide)
if __name__ == "__main__":
main()