Test avec opérateur logique 2
Exercice
Écrire un programme Python qui affiche "au moins deux égales
" si au moins deux valeurs des variables a
, b
et c
sont égales et "au moins deux différentes
" sinon.
#à compléterbackslash_newline# doit fonctionner pour tout triplet de valeurs de (a,b,c) de type intbackslash_newlinea = 841backslash_newlineb = 841backslash_newlinec = 842backslash_newlinebackslash_newline#Solution 1backslash_newline# doit fonctionner pour tout triplet de valeurs de (a,b,c) de type intbackslash_newlinea = 841backslash_newlineb = 841backslash_newlinec = 842backslash_newlineif a == b or a == c or b == c:backslash_newline print("Au moins deux égales")backslash_newlineelse:backslash_newline print("Au moins deux différentes")backslash_newlinebackslash_newline#Solution 2 : on inverse les blocs en prenant la négation de la conditionbackslash_newline# doit fonctionner pour tout triplet de valeurs de (a,b,c) de type intbackslash_newlinea = 841backslash_newlineb = 841backslash_newlinec = 842backslash_newlineif a != b and a != c and b != c:backslash_newline print("Au moins deux différentes") backslash_newlineelse:backslash_newline print("Au moins deux égales")backslash_newlinebackslash_newlinebackslash_newline