Exercice 39
Ecrire un programme en Python qui prend en entrée un dictionnaire de prix d'articles et de quantités vendues, puis calcule le chiffre d'affaires total.
Exemple pour le dictionnaire suivant:
|
1 2 3 4 5 |
inventaire = { 'article1': (10, 5), 'article2': (5, 8), 'article3': (8, 3) } |
l'algorithme renvoie le chiffre d'affaire : 10x5 + 5x8 + 8x3 = 114
Solution
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
def calculer_chiffre_affaires(inventaire): chiffre_affaires = 0 for article, (prix, quantite) in inventaire.items(): chiffre_affaires += prix * quantite return chiffre_affaires # Exemple d'utilisation : inventaire = { 'article1': (10, 5), 'article2': (5, 8), 'article3': (8, 3) } resultat = calculer_chiffre_affaires(inventaire) print(f"Le chiffre d'affaires total est : {resultat}") # output : Le chiffre d'affaires total est : 114 |
Younes Derfoufi
CRMEF OUJDA

![[App intégrée] 2025 Upgraded Vidéoprojecteur 1920 * 1080P FHD 4K Mini Projecteur Portable Dual Contrôle avec Souris Android TV WiFi 6 BT5.2 180° Rotation Compatible avec HDMI/TV Stick/USB](https://www.tresfacile.net/wp-content/uploads/2025/12/Videoprojecteur-1920-1080P-FHD-4K-Mini-Projecteur-Portable-Dual-Control-250x236.png)
