From 6475d0c65e54802af2c9ee9c89179e42f176e696 Mon Sep 17 00:00:00 2001 From: Dahmane Lynda <lynda.dahmane.etu@118p28.fil.univ-lille.fr> Date: Wed, 31 Jan 2024 11:48:29 +0100 Subject: [PATCH] =?UTF-8?q?tp3=20fin=20s=C3=A9ance?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fractales => }/ap_decorators.py | 0 Tp3/fibonacci.py | 32 +++++++++++++ Tp3/fractals.py | 46 +++++++++++++++++++ Tp3/tracing_recurcing.py | 45 +++++++++++++++++- 4 files changed, 122 insertions(+), 1 deletion(-) rename Tp3/{Recursion/fractales => }/ap_decorators.py (100%) create mode 100644 Tp3/fibonacci.py create mode 100644 Tp3/fractals.py 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 0000000..a2dc3a5 --- /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 0000000..90bfa58 --- /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 d083708..d177edb 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 + + + -- GitLab