Exercice 21
Ecrire un programme en python qui renvoie le produit cartésien des deux ensembles suivants:
|
1 2 |
E = {'a' , 'b' , 'c' , 'd'} F = {'x' , 'y' , 'z' } |
Solution
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
E = {'a' , 'b' , 'c' , 'd'} F = {'x' , 'y' , 'z' } # initialisation du produit cartésien de E et F ExF = set({}) for x in E: for y in F: ExF.add((x,y)) # afficher le produit cartésien de E et F print("ExF = " , ExF) """ output: ExF = {('a', 'z'), ('d', 'y'), ('d', 'x'), ('a', 'x'), ('b', 'x'), ('d', 'z'), ('c', 'y'), ('c', 'x'), ('a', 'y'), ('b', 'z'), ('c', 'z'), ('b', 'y')} """ |
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)

1 thought on “Solution Exercice 21: produit cartésien de deux ensembles en python”