Exercice6
Ecrire un programme en langage Python qui renvoie l'intersection et la réunion des trois ensembles suivants:
1 2 3 |
A = {11 , 21 , 5 , 7 , 43 , 32 , 13 , 9} B = {2 , 19 , 11 , 33 , 7 , 25 , 5 , 4} C = {45 ,27 , 11 , 5 , 7 , 22 , 14 , 1} |
Solution
1 2 3 4 5 6 7 8 9 10 11 |
A = {11 , 21 , 5 , 7 , 43 , 32 , 13 , 9} B = {2 , 19 , 11 , 33 , 7 , 25 , 5 , 4} C = {45 ,27 , 11 , 5 , 7 , 22 , 14 , 1} # Intersection des trois ensembles I = A.intersection(B.intersection(C)) print(I) # output: {11, 5, 7} # réunion des trois ensembles R = A.union(B.union(C)) print(R) # output: {1, 2, 4, 5, 7, 9, 11, 13, 14, 19, 21, 22, 25, 27, 32, 33, 43, 45} |
Younes Derfoufi
CRMEF OUJDA
2 thoughts on “Solution Exercice6: réunion et intersection de trois ensembles en python”