From e1b01ced86d18341d51341f2e496c35a19af0936 Mon Sep 17 00:00:00 2001 From: Tipragot Date: Wed, 27 Sep 2023 11:11:47 +0200 Subject: [PATCH] Exercice H --- Chapitre 2 - Récursivité/exercices.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Chapitre 2 - Récursivité/exercices.py b/Chapitre 2 - Récursivité/exercices.py index d051e67..ee2ee79 100644 --- a/Chapitre 2 - Récursivité/exercices.py +++ b/Chapitre 2 - Récursivité/exercices.py @@ -76,4 +76,20 @@ def bhaut(n: int): """ if n == 0: return # Si n est égal a 0 on ne fais rien print("*" * n) # On affiche n points - bhaut(n-1) # On fait appel à la fonction avec n-1 points pour afficher la ligne suivante \ No newline at end of file + 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 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