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

QCM : Fonctions Python et calculs

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

Objectifs travaillés

Ce QCM porte sur l'utilisation des fonctions Python pour effectuer des calculs : appels, fonctions par morceaux et fonctions contenant des boucles. Choisissez la bonne réponse parmi les quatre propositions.

Déroulement pas à pas (Correction et Indices)

Question 1 :

On définit la fonction Python ci-dessous :

def carre(x) :
    return x * x

Que vaut carre(7) ?

  • (Incorrect) $14$
  • (Correct) $49$
  • (Incorrect) $7$
  • (Incorrect) $2$
Question 2 :

On définit la fonction Python ci-dessous :

def f(x) :
    if x < 0 :
        return -x
    else :
        return x ** 2

Que vaut f(-3) ?

  • (Incorrect) $-3$
  • (Incorrect) $9$
  • (Correct) $3$
  • (Incorrect) $-9$
Question 3 :

On reprend la même fonction Python :

def f(x) :
    if x < 0 :
        return -x
    else :
        return x ** 2

Que vaut f(4) ?

  • (Incorrect) $-4$
  • (Incorrect) $8$
  • (Correct) $16$
  • (Incorrect) $4$
Question 4 :

On définit la fonction Python ci-dessous :

def somme_carres(n) :
    S = 0
    for i in range(1, n+1) :
        S = S + i**2
    return S

Que vaut somme_carres(3) ?

  • (Incorrect) $6$
  • (Correct) $14$
  • (Incorrect) $9$
  • (Incorrect) $36$
Question 5 :

On définit la fonction Python ci-dessous :

def somme(a, b) :
    return a + b

Que vaut somme(somme(2, 3), somme(4, 5)) ?

  • (Incorrect) $9$
  • (Incorrect) $20$
  • (Correct) $14$
  • (Incorrect) $5$
Question 6 :

On définit la fonction Python ci-dessous :

def compter_pairs(n) :
    c = 0
    for i in range(1, n+1) :
        if i % 2 == 0 :
            c = c + 1
    return c

Que vaut compter_pairs(10) ?

  • (Incorrect) $10$
  • (Correct) $5$
  • (Incorrect) $4$
  • (Incorrect) $0$