QCM : Conditions composées et prédictions de sortie
Créez un compte gratuit pour suivre votre avancement et reprendre où vous avez laissé.
Créer un compteObjectifs travaillés
Ce QCM porte sur les conditions composées, les fonctions par morceaux et les pièges classiques autour des structures conditionnelles en Python. Choisissez la bonne réponse parmi les quatre propositions.
Déroulement pas à pas (Correction et Indices)
Question 1 : On exécute le programme Python ci-dessous :
age = 16
if age < 6 :
tarif = 0
elif age < 12 :
tarif = 5
elif age < 18 :
tarif = 8
else :
tarif = 12
print(tarif)
Que s'affiche-t-il ?
age = 16
if age < 6 :
tarif = 0
elif age < 12 :
tarif = 5
elif age < 18 :
tarif = 8
else :
tarif = 12
print(tarif)- (Incorrect) $5$
- (Correct) $8$
- (Incorrect) $12$
- (Incorrect) $0$
Question 2 : Avec x = 4, que vaut l'expression (x > 0 and x < 5) or x == 10 en Python ?
- (Incorrect) False
- (Correct) True
- (Incorrect) $4$
- (Incorrect) Une erreur est provoquée
Question 3 : Le programme Python ci-dessous affecte une valeur à b :
x = -3
b = (x >= 0)
Que vaut l'expression not b ?
x = -3
b = (x >= 0)- (Incorrect) False
- (Correct) True
- (Incorrect) $-3$
- (Incorrect) Une erreur est provoquée
Question 4 : On considère la fonction Python ci-dessous :
def f(x) :
if x < -1 :
return x**2
elif x <= 1 :
return 2*x
else :
return x + 3
Que vaut f(1) ?
def f(x) :
if x < -1 :
return x**2
elif x <= 1 :
return 2*x
else :
return x + 3- (Incorrect) $1$
- (Incorrect) $4$
- (Correct) $2$
- (Incorrect) $-1$
Question 5 : On exécute le programme Python ci-dessous (l'utilisateur saisit henri en minuscules) :
nom = input("Votre nom : ")
if nom == "Henri" :
print("Bonjour Henri")
else :
print("Bonjour inconnu")
Que s'affiche-t-il ?
nom = input("Votre nom : ")
if nom == "Henri" :
print("Bonjour Henri")
else :
print("Bonjour inconnu")- (Incorrect) Bonjour Henri
- (Correct) Bonjour inconnu
- (Incorrect) Bonjour henri
- (Incorrect) Une erreur est provoquée
Question 6 : Avec x = 5 et y = 10, que vaut l'expression not (x > y) and y > 0 en Python ?
- (Incorrect) False
- (Incorrect) None
- (Correct) True
- (Incorrect) Une erreur est provoquée