Python au lycée (2) : Les instructions conditionnelles Entraînement

QCM : Structures if, elif, else en Python

Durée estimée
10 minutes
Difficulté
Votre progression

Créez un compte gratuit pour suivre votre avancement et reprendre où vous avez laissé.

Créer un compte

Objectifs travaillés

Ce QCM porte sur les structures conditionnelles Python : if, elif, else, indentation et prédiction de sortie. 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 :

x = -3
if x > 0 :
    print("positif")
else :
    print("négatif ou nul")

Que s'affiche-t-il ?

  • (Incorrect) positif
  • (Correct) négatif ou nul
  • (Incorrect) positif puis négatif ou nul
  • (Incorrect) Rien ne s'affiche
Question 2 :

On exécute le programme Python ci-dessous :

note = 12
if note >= 16 :
    print("Très bien")
elif note >= 12 :
    print("Bien")
elif note >= 10 :
    print("Passable")
else :
    print("Insuffisant")

Que s'affiche-t-il ?

  • (Incorrect) Très bien
  • (Correct) Bien
  • (Incorrect) Passable
  • (Incorrect) Bien puis Passable
Question 3 :

Avec x = 1 et y = 2, que vaut l'expression x == 1 and y == 3 en Python ?

  • (Incorrect) True
  • (Correct) False
  • (Incorrect) 1
  • (Incorrect) Une erreur est provoquée
Question 4 :

On souhaite tester si la variable x est égale à $5$. Laquelle des instructions ci-dessous est correcte en Python ?

  • (Incorrect) if x = 5 :
  • (Incorrect) if x == 5
  • (Correct) if x == 5 :
  • (Incorrect) if x := 5 :
Question 5 :

On exécute le programme Python ci-dessous :

def f(x) :
    if x <= 0 :
        return -x + 1
    else :
        return 3*x + 1

print(f(-2))

Que s'affiche-t-il ?

  • (Incorrect) $-5$
  • (Correct) $3$
  • (Incorrect) $-1$
  • (Incorrect) $7$
Question 6 :

On exécute le programme Python ci-dessous :

x = 7
est_positif = (x > 0)
if est_positif :
    print("A")
else :
    print("B")

Que s'affiche-t-il ?

  • (Incorrect) B
  • (Incorrect) True
  • (Correct) A
  • (Incorrect) Une erreur est provoquée