diff --git a/Tp3/Recursion/fractales/ap_decorators.py b/Tp3/ap_decorators.py similarity index 100% rename from Tp3/Recursion/fractales/ap_decorators.py rename to Tp3/ap_decorators.py diff --git a/Tp3/fibonacci.py b/Tp3/fibonacci.py new file mode 100644 index 0000000000000000000000000000000000000000..a2dc3a530955b1631f53d142f01d42d47f08f21d --- /dev/null +++ b/Tp3/fibonacci.py @@ -0,0 +1,32 @@ +#Q1: +# on calcul les nombres de fibonacci jusqu'à n=10: +#f_0=0 etf_1=1 +#f_2=f_1+f_0=1+0=1....f_9=f_8+f_7=21+13=24, et f_10=f_9+f_8=34+21=55 + +from ap_decorators import count +@count +def fibo(n:int)->int: + """renvoie les termes de la suite Fibonacci + + Précondition : + Exemple(s) : + $$$ fibo(10) + 55 + $$$ fibo(8) + 21 + $$$ fibo(1) + 1 + + """ + if n<=1: + return n + else: + return fibo (n-1)+fibo(n-2) + +#fibo(40) donne : 102334155 , que f_40 est assez grand , donc les nombres de la suite fibonacci +#peuvent devenir grands à mesure que n augmente. + + + + + \ No newline at end of file diff --git a/Tp3/fractals.py b/Tp3/fractals.py new file mode 100644 index 0000000000000000000000000000000000000000..90bfa581ffde61d7ea471ca77f3c055c2766e826 --- /dev/null +++ b/Tp3/fractals.py @@ -0,0 +1,46 @@ +import turtle + + +def zigzag(): + """à_remplacer_par_ce_que_fait_la_fonction + + Précondition : + Exemple(s) : + $$$ + + """ + if + + turtle.left(45) + turtle.forward(50) + turtle.rieght(100) + turtle.forward(45) + + turtle.left(45) + turtle.forward(50) + turtle.rieght(100) + turtle.forward(45) + + turtle.left(45) + turtle.forward(50) + turtle.rieght(100) + turtle.forward(45) + + + turtle.left(45) + turtle.forward(50) + turtle.rieght(100) + turtle.forward(45) + + + + turtle.left(45) + turtle.forward(50) + turtle.rieght(100) + turtle.forward(45) + + + + + + diff --git a/Tp3/tracing_recurcing.py b/Tp3/tracing_recurcing.py index d08370815411587fd6b67d457b7400457222f627..d177edb566a5db3aef64059decf5a8b028de5f96 100644 --- a/Tp3/tracing_recurcing.py +++ b/Tp3/tracing_recurcing.py @@ -1,6 +1,9 @@ #Dahmane lynda #TP3 #31/01/2024 + +from ap_decorators import trace +@trace def somme(a:int,b:int)->int: """renvoie la somme des deux entiers a et b @@ -16,4 +19,44 @@ def somme(a:int,b:int)->int: res=b else: res=somme(a-1,b+1) - return res \ No newline at end of file + return res + +@trace +def binomial(n:int,k:int)->int: + """renvoie le coefficient binomial ,qui represente le nombre de façon +de choisir k elements parmis un ensemble de n elements. + + Précondition : + Exemple(s) : + $$$ binomial(7,3) + 35 + + """ + if k==0 or k==n: + return 1 + else: + return binomial(n-1,k-1)+binomial(n-1,k) + + +@trace +def is_palindromic(mot:str)->bool: + """renvoie True si le mot est un palindromic sinon renvoie False + + Précondition : + Exemple(s) : + $$$ is_palindromic("radar") + True + $$$ is_palindromic("hello") + False + + """ + + if len(mot)<=1: + return True + elif mot[0]==mot[-1]: + return is_palindromic(mot[1:-1]) + else: + return False + + +