TS 7 DST 2 correction 16 octobre 2014
Exercice 1 : —
Le signe est 0 donc c’est un nombre positif.
— La partie exposant est 10001000 donc 136 en d´ecimal, en retranchant 127 on obtient 9.
— La mantisse est le reste, c’est `a dire 1,1001 ou en d´ecimal 1+1/2+1/16 = 1,52625.
On obtient donc le nombre :
1,52625×29= 800.
Exercice 2 :
(1) Six= 4, on obtient l’affichageGagne puisx vaut 4 puisx different de 4 (attention `a l’indentation)
Si x=−1, on obtient l’affichageperdupuisx different de 4 (2) Six=−2 on obtient l’affichagex est negatif
Si x= 4 on obtient l’affichatex est positif Si x= 0 on obtient l’affichagex est positif
Exercice 3 :
On utilise la fonction suivante :
1
def tarif poste ( type , poids ):
2
if type == " verte ":
3
if poids == " 20 ":
4
return 0.57
5
elif poids == " 50 ":
6
return 0.95:
7
else :
8
return 1.40
9
elif type == " prioritaire "
10
if poids == " 20 ":
11
return 0.6
12
elif poids == " 50 ":
13
return 1:
14
else :
15
return 1.45
16
else :
17
if poids == " 20 ":
18
return 0.55
19
elif poids == " 50 ":
20
return 0.78:
21
else :
22
return 1
Exercice 4 :
(1) Il manque l’initialisation de la boucle. Entre la ligne 2 et 3, on doit rajouter i
= 0 (2)
1
def factorielle (n ):
2
a = 1
3
for i in range (n ):
4
a = a
∗i
5
return a
Exercice 5 :
(1) La fonction renvoie 9.
(2) Cette fonction calcule le maximum de la liste.
(3) On utilise la fonction :
1
def max (L ):
2
tmp = L [0]
3
indice = 0
4
longueur = len (L)
5
for i in range( longueur ):
6
if tmp
<L[i ]:
7
tmp = L[i]
8
indice = i
9
return indice
Exercice 6 :
1
def max(L ):
2
tmp = L [0]
3
indice = 0
4
longueur = len (L)
5
for i in range ( longueur ):
6
if tmp
<L[i ]:
7
tmp = L[i]
8
indice = i
9
return indice
Exercice 7 :
1
def Somme (L ):
2
somme = 0
3
longueur = len (L)
4
for i in range ( longueur ):
5
somme = L[i] + somme
6