Skip to content
Snippets Groups Projects
Commit 6475d0c6 authored by Dahmane Lynda's avatar Dahmane Lynda
Browse files

tp3 fin séance

parent b31f94b1
Branches
No related tags found
No related merge requests found
File moved
#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
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)
#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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment