From f1daf341ecc15d0e0e8de546c1594576c300e75d Mon Sep 17 00:00:00 2001 From: Tipragot Date: Wed, 4 Oct 2023 10:39:06 +0200 Subject: [PATCH] Ajout bbas --- Chapitre 2 - Récursivité/exercices.py | 33 +++++++++++++++------------ 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/Chapitre 2 - Récursivité/exercices.py b/Chapitre 2 - Récursivité/exercices.py index 68a3095..8c9e0e3 100644 --- a/Chapitre 2 - Récursivité/exercices.py +++ b/Chapitre 2 - Récursivité/exercices.py @@ -78,18 +78,23 @@ def bhaut(n: int): print("*" * n) # On affiche n points bhaut(n-1) # On fait appel à la fonction avec n-1 points pour afficher la ligne suivante - def pair(n: int) -> bool: - """ - Fonction récursive qui renvoie True si n est pair et False sinon. - """ - if n == 0: # Si n est égal a 0 alors - return True # On renvoie True pour dire que c'est pair - return impair(n-1) # Sinon on fait appel à la fonction impair avec n-1 +def bbas(n: int): + if n == 0: return # Si n est égal a 0 on ne fais rien + bbas(n-1) # On fait appel à la fonction avec n-1 points pour afficher la ligne suivante + print("*" * n) # On affiche n points + +def pair(n: int) -> bool: + """ + Fonction récursive qui renvoie True si n est pair et False sinon. + """ + if n == 0: # Si n est égal a 0 alors + return True # On renvoie True pour dire que c'est pair + return impair(n-1) # Sinon on fait appel à la fonction impair avec n-1 - def impair(n: int) -> bool: - """ - Fonction récursive qui renvoie True si n est impair et False sinon. - """ - if n == 0: # Si n est égal a 0 alors - return False # On renvoie False pour dire que cc n'est pas impair - return pair(n-1) # Sinon on fait appel à la fonction pair avec n-1 \ No newline at end of file +def impair(n: int) -> bool: + """ + Fonction récursive qui renvoie True si n est impair et False sinon. + """ + if n == 0: # Si n est égal a 0 alors + return False # On renvoie False pour dire que cc n'est pas impair + return pair(n-1) # Sinon on fait appel à la fonction pair avec n-1 \ No newline at end of file