QCM : Boucles for et range en Python
Créez un compte gratuit pour suivre votre avancement et reprendre où vous avez laissé.
Créer un compteObjectif travaillé
Ce QCM porte sur la boucle for et la fonction range en Python. Choisissez la bonne réponse parmi les quatre propositions.
Déroulement pas à pas (Correction et Indices)
Question 1 : Quelles valeurs parcourt range(5) en Python ?
- (Incorrect) $1, 2, 3, 4, 5$
- (Correct) $0, 1, 2, 3, 4$
- (Incorrect) $0, 1, 2, 3, 4, 5$
- (Incorrect) $5$
Question 2 : Quelles valeurs parcourt range(2, 6) en Python ?
- (Incorrect) $2, 3, 4, 5, 6$
- (Correct) $2, 3, 4, 5$
- (Incorrect) $3, 4, 5$
- (Incorrect) $2, 6$
Question 3 : Combien de fois le bloc d'instructions de la boucle ci-dessous est-il exécuté ?
for i in range(10) :
print("Bonjour")
for i in range(10) :
print("Bonjour")- (Incorrect) $9$
- (Incorrect) $11$
- (Correct) $10$
- (Incorrect) $1$
Question 4 : On exécute le programme Python ci-dessous :
for i in range(3) :
print(i, end=' ')
Que s'affiche-t-il ?
for i in range(3) :
print(i, end=' ')- (Correct) 0 1 2
- (Incorrect) 1 2 3
- (Incorrect) 0 1 2 3
- (Incorrect) 3
Question 5 : Quand on ne sait pas à l'avance combien de fois il faudra répéter un bloc (car cela dépend d'une condition à vérifier), quelle instruction Python utilise-t-on ?
- (Incorrect) for
- (Correct) while
- (Incorrect) if
- (Incorrect) range
Question 6 : On exécute le programme Python ci-dessous :
for i in [1, 3, 5] :
print(2*i, end=' ')
Que s'affiche-t-il ?
for i in [1, 3, 5] :
print(2*i, end=' ')- (Incorrect) 1 3 5
- (Incorrect) 2 4 6
- (Correct) 2 6 10
- (Incorrect) Une erreur est provoquée