0% found this document useful (0 votes)
13 views4 pages

Exercices Python 16-25

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views4 pages

Exercices Python 16-25

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

✅ Exercice 16 : Méthodes listes

Notes = [14,9,16,12,5,17,8,15]

Notes.sort()

Print(notes)

Notes.reverse()

Print(notes)

Print([5,2,5,8,5,1,5].count(5))

Couleurs = [“rouge”, “bleu”, “vert”]

Couleurs.extend([“jaune”, “violet”])

Print(couleurs)

Couleurs.clear()

Print(couleurs)

✅ Exercice 17 : Listes de listes

Matrice = [[1,2,3], [4,5,6], [7,8,9]]

Print(matrice[1][2])

For I in range(3):

For j in range(3):

Print(f”{i},{j}={matrice[i][j]}”)

Print(sum([sum(ligne) for ligne in matrice]))

✅ Exercice 18 : Chaînes ↔ listes

Print(“Python est génial”.split())

Mots = [“Python”, “est”, “un”, “langage”, “puissant”]

Print(“ “.join(mots))
Print(list(“Python”))

Caracteres = [‘P’, ‘y’, ‘t’, ‘h’, ‘o’, ‘n’]

Print(“”.join(caracteres))

Phrase = input(“Phrase : “)

Print([m for m in phrase.split() if len(m) > 3])

✅ Exercice 19 : Compréhensions

Carres = [x**2 for x in range(1, 11)]

Pairs = [x for x in range(1, 11) if x % 2 == 0]

Mots = [“Python”, “langage”, “programmation”, “liste”, “compréhension”]

Longueurs = [len(m) for m in mots]

Communes = [c for c in “python” if c in “programmation”.lower()]

Matrice = [[I + j for j in range(5)] for I in range(5)]

✅ Exercice 21 : Salaires

Employes = [“Ali”, “Awa”, “Omar”, “Lina”, “Zoe”]

Salaires = [300000, 250000, 400000, 270000, 320000]

Print(sum(salaires), sum(salaires)/len(salaires))

Print(employes[salaires.index(max(salaires))])

Nouv = [s*1.05 if s < 300000 else s for s in salaires]

Print(nouv)

✅ Exercice 22 : Inventaire

Inventaire = [[“riz”, 20, 300], [“huile”, 10, 500], [“sel”, 5, 100]]

Def total():

Return sum(q * p for _, q, p in inventaire)


Def seuil(seuil):

Return [I for I in inventaire if i[1] < seuil]

Def vente(nom, qte):

For prod in inventaire:

If prod[0] == nom and prod[1] >= qte:

Prod[1] -= qte

✅ Exercice 23 : Ventes

Ventes = [10,12,9,8,14,13,11,15,10,9,7,16]

Print(sum(ventes))

Print(max(ventes), min(ventes))

Q1 = sum(ventes[:3])/3

Q2 = sum(ventes[3:6])/3

Q3 = sum(ventes[6:9])/3

Q4 = sum(ventes[9:])/3

Print(max(q1, q2, q3, q4))

For v in ventes:

Print(“*” * v)

✅ Exercice 24 : Clients

Clients = [[“Ali”, [email protected], “123”, 600000],

[“Awa”, [email protected], “456”, 450000]]

Def add©: clients.append©

Def recherche(val):

Return [c for c in clients if val in c]


Def premium():

Return [c for c in clients if c[3] > 500000]

Def top3():

Return sorted(clients, key=lambda x: x[3], reverse=True)[:3]

✅ Exercice 25 : Finance

Revenus = [500, 600, 550, 700]

Depenses = [400, 650, 500, 800]

Resultats = [r – d for r, d in zip(revenus, depenses)]

Marges = [round((r – d) / r * 100, 2) for r, d in zip(revenus, depenses)]

Print([I for I, (r, d) in enumerate(zip(revenus, depenses)) if d > r])

Def roi(invest, flux):

Return (sum(flux) – invest) / invest * 100

You might also like