def addition(x, y):
return x + y
def soustraction(x, y):
return x - y
print(addition(5, 7))
print(addition(3, 2))
print(addition(14, 6))
12 5 20
print(soustraction(5, 7))
print(soustraction(3, 2))
print(soustraction(14, 6))
-2 1 8
def factorielle(x):
if x <= 1:
return 1
else: return x * factorielle(x-1)
factorielle(5)
120
def jaccard(x, y):
#intersection entre les deux ensembles
intersection = []
for elt in x:
if elt in y:
intersection.append(elt)
print("intersection")
print(intersection)
#union entre les deux ensembles
union = []
for elt in x:
union.append(elt)
for elt in y:
if elt not in x:
union.append(elt)
print("union")
print(union)
#calcul
return len(intersection)/len(union)
jaccard([5,6,8,3,1],[3,8,6,1,6])
intersection [6, 8, 3, 1] union [5, 6, 8, 3, 1]
0.8
from math import sqrt
def racines_polynome(a, b, c):
#calcul du déterminant
determinant = b*b - 4* a * c
#conditions
if determinant < 0:
print("Il n'y a pas de racines")
elif determinant == 0:
print("une seule racine")
print(-b/(2*a))
else:
print("deux racines")
print((-b+sqrt(determinant))/(2*a))
print((-b-sqrt(determinant))/(2*a))
racines_polynome(5, 5, -10)
deux racines 1.0 -2.0
from math import sqrt
def racines_polynome(a, b=0, c=0):
#calcul du déterminant
determinant = b*b - 4* a * c
#conditions
if determinant < 0:
print("Il n'y a pas de racines")
elif determinant == 0:
print("une seule racine")
print(-b/(2*a))
else:
print("deux racines")
print((-b+sqrt(determinant))/(2*a))
print((-b-sqrt(determinant))/(2*a))
racines_polynome(a=1, b=-8)
deux racines 8.0 0.0
from operations import racines_polynome as racines
racines(a=1, b=-8)
deux racines 8.0 0.0
from operations import racines_polynome as poly
poly(1,-8)
deux racines 8.0 0.0
from operations import sous_parties
sous_parties(["lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi", "dimanche"])
['lund', 'mard', 'merc', 'jeud', 'vend', 'same', 'dima']