0% found this document useful (0 votes)
4 views7 pages

Corrige Python-2

liufyudtrytyu

Uploaded by

leondamas11
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views7 pages

Corrige Python-2

liufyudtrytyu

Uploaded by

leondamas11
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Corrigé — Évaluation de Python

Durée : 2H | Chaque exercice noté sur 2 points


Exercice 1 : Valeurs des listes

a = list(range(6))
➜ a = [0, 1, 2, 3, 4, 5]

a = list(range(10, 14))
➜ a = [10, 11, 12, 13]

a = list(range(20, 35, 3))


➜ a = [20, 23, 26, 29, 32]

a = list(range(2024, 2026))
➜ a = [2024, 2025]

Exercice 2 : Trace du programme

m = 15
if m%4 >= 3:
m += 5
m = 2*m
m *= 10
print(m)

Détails :
m = 15
m % 4 = 3 → 3 >= 3 : True
m += 5 → m = 20
m = 2*m → m = 40
m *= 10 → m = 400

➜ Affichage : 400

Exercice 3 : Trace du programme

x = 2
y = 10
if (y//3) > 4:
x -= 7
else:
x = x + y
x = 5*x
print(x)

Détails :
x = 2, y = 10
y // 3 = 3 → 3 > 4 : False → else
x = x + y = 2 + 10 = 12
x = 5 * 12 = 60

➜ Affichage : 60

Exercice 4 : Trace du programme

som = 0
for i in range(3, 6):
som += i
som = som + 6
print(som)

Détails :
som = 0
i = 3 → som = 0 + 3 = 3
i = 4 → som = 3 + 4 = 7
i = 5 → som = 7 + 5 = 12
som = 12 + 6 = 18

➜ Affichage : 18

Exercice 5 : Trace du programme

liste = [2, 5, 6]
p = 1
for j in liste:
p = p*j
p *= 2
print(p)

Détails :
liste = [2, 5, 6], p = 1
j = 2 → p = 1 * 2 = 2
j = 5 → p = 2 * 5 = 10
j = 6 → p = 10 * 6 = 60
p *= 2 → p = 120

➜ Affichage : 120

Exercice 6 : Trace du programme

n = 20
while (n%6) != 0:
n = n - 1
n += 5
print(n)
Détails :
n = 20 → 20 % 6 = 2 ≠ 0 → n = 19
n = 19 → 19 % 6 = 1 ≠ 0 → n = 18
n = 18 → 18 % 6 = 0 → sortie de la boucle
n += 5 → n = 23

➜ Affichage : 23
Exercice 7 : Valeurs de y et w

def solution(a, b, c):


d = b**2 - 4*a*c
x = d + 10
return x

y = solution(2, 3, 5)
w = solution(1, 2, -1)

Pour y = solution(2, 3, 5) :
d = 3**2 - 4*2*5 = 9 - 40 = -31
x = -31 + 10 = -21
➜ y = -21

Pour w = solution(1, 2, -1) :


d = 2**2 - 4*1*(-1) = 4 + 4 = 8
x = 8 + 10 = 18
➜ w = 18

Exercice 8 : Valeurs de a, b, c et d

from math import *


a = sqrt(36)
b = floor(10.9)
c = degrees(pi)
d = 5 - 2*sqrt(9)

a = sqrt(36) → a = 6.0
b = floor(10.9) → b = 10
c = degrees(pi) → c = 180.0
d = 5 - 2*sqrt(9) → d = 5 - 6.0 = -1.0

➜ a = 6.0 b = 10 c = 180.0 d = -1.0

Exercice 9 : Correction des erreurs

Code 1 — Erreur : s inutilisé, intention = sommer


s = 0 # correction : s = 0 (pas 1)
for i in range(4):
s += i # ajout du cumul
print(s) # affiche 6

Code 2 — Erreur : indentation de x += j


x = 0
for j in range(2, 3):
x += j # correction : indenter
print(x)

Code 3 — Erreur : deux-points manquants après else


m = 0
if m >= 0:
m = m + 1
else: # correction : ajouter ':'
m = m - 1

Code 4 — Erreur : formule du volume incorrecte


from math import pi

def volume(r, h):


v = pi * r**2 * h # correction : formule cylindre
return v

Exercice 10 : Application IoT — LYNAQE

Question 1 — Code secret


code = int(input('Entrez le code secret : '))
if code == 2626:
print('Acces autorise')
else:
print('Acces refuse')

Question 2 — Fonction consommation


def consommation(n):
P = 150 * n
return P

La fonction prend en paramètre n (nombre de lampes allumées),


calcule P = 150 × n et retourne la consommation totale en watts.

You might also like