Python au lycée (4) : Les fonctions Entraînement

QCM : Modules math et random en Python

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

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

Créer un compte

Objectif travaillé

Ce QCM porte sur les modules Python math et random : import, fonctions sqrt, randint, random et simulations. Choisissez la bonne réponse parmi les quatre propositions.

Déroulement pas à pas (Correction et Indices)

Question 1 :

Pour utiliser la fonction sqrt (racine carrée), laquelle des instructions suivantes est correcte ?

  • (Incorrect) import sqrt
  • (Correct) from math import sqrt
  • (Incorrect) include math.sqrt
  • (Incorrect) math.sqrt()
Question 2 :

On exécute le programme Python ci-dessous :

from random import randint
n = randint(2, 5)

Parmi les valeurs suivantes, laquelle peut être affectée à n ?

  • (Incorrect) $1$
  • (Incorrect) $6$
  • (Correct) $3$
  • (Incorrect) $2.5$
Question 3 :

Que renvoie la fonction random() du module random en Python ?

  • (Incorrect) Un entier aléatoire entre $0$ et $1$
  • (Incorrect) Un décimal aléatoire entre $0$ et $1$, les deux bornes incluses
  • (Correct) Un décimal aléatoire dans $[0\,;\,1[$ (borne supérieure exclue)
  • (Incorrect) Un décimal aléatoire entre $-1$ et $1$
Question 4 :

On exécute le programme Python ci-dessous :

def carre(x) :
    return x * x

def double(x) :
    return 2 * x

print(carre(double(3)))

Que s'affiche-t-il ?

  • (Incorrect) $12$
  • (Incorrect) $18$
  • (Correct) $36$
  • (Incorrect) $6$
Question 5 :

On exécute le programme Python ci-dessous :

from math import sqrt
print(sqrt(16) + sqrt(9))

Que s'affiche-t-il ?

  • (Incorrect) $5$
  • (Incorrect) $25$
  • (Correct) $7.0$
  • (Incorrect) $5.0$
Question 6 :

On exécute le programme Python ci-dessous sur un ordinateur puissant :

from random import randint

def frequence_six(n) :
    nb = 0
    for i in range(n) :
        if randint(1, 6) == 6 :
            nb = nb + 1
    return nb / n

print(frequence_six(100000))

Quelle valeur approximative s'affiche typiquement ?

  • (Incorrect) $0.1$ exactement
  • (Incorrect) $0.5$ environ
  • (Correct) $0.167$ environ (proche de $1/6$)
  • (Incorrect) $6$ environ