QCM
int et float☘
Rappel
Les questions ci-dessous sont là pour vous aider à contrôler ce que vous avez retenu.
Si vous ne répondez pas à toutes les questions sans hésitation, c'est sans doute qu'il faut retravailler les pages précédentes.
Pour chaque question, il faut trouver la (ou les) bonne(s) réponse(s).
QCM 1☘
Dans l'interpréteur python, on saisit l'instruction :
>>> 3 + 2.0
Alors :
- On obtient une erreur «
TypeError: unsupported operand type(s) for +: 'int' and 'float'». - On obtient
5.0 - Le résultat est de type
int - Le résultat est de type
float
Réponse
- On obtient une erreur «
TypeError: unsupported operand type(s) for +: 'int' and 'float'». - On obtient
5.0 - Le résultat est de type
int - Le résultat est de type
float
QCM 2☘
Dans l'interpréteur python, on saisit l'instruction :
>>> 3 + 12/4
Alors :
- On obtient
6 - On obtient
6.0 - Le résultat est de type
int - Le résultat est de type
float
Réponse
L'opérateur « / » donne toujours un float et pour additionner un int (ici 3) et un float (3.0 = 12/4), Python transforme d'abord l'objet de type int en un objet de type float puis ajoute les float.
- On obtient
6 - On obtient
6.0 - Le résultat est de type
int - Le résultat est de type
float
QCM 3☘
Dans l'interpréteur python, on saisit l'instruction :
>>> 2//3
Alors :
- On obtient
0 - On obtient
0.6666666666666666 - Le résultat est de type
int - Le résultat est de type
float
Réponse
2//3 est le quotient de la division entière de 2 par 3: 2 = 3×0+2.
- On obtient
0 - On obtient
0.6666666666666666 - Le résultat est de type
int - Le résultat est de type
float
QCM 4☘
Dans l'interpréteur python, on saisit l'instruction :
>>> 2**3
Alors :
- On obtient une erreur
- On obtient
6 - On obtient
8 - On obtient
9
Réponse
2**3 = 23 = 2×2×2 = 8.
- On obtient une erreur
- On obtient
6 - On obtient
8 - On obtient
9
QCM 5☘
Dans l'interpréteur python, on saisit l'instruction :
>>> 2**3.0
Alors :
- On obtient une erreur
- On obtient
8 - On obtient
8.0 - On obtient
9.0
Réponse
- On obtient une erreur
- On obtient
8 - On obtient
8.0 - On obtient
9.0
QCM 6☘
Dans l'interpréteur python, on saisit l'instruction :
>>> 2**3.0
Alors :
- On obtient une erreur
- On obtient
8 - On obtient
8.0 - On obtient
9.0
Réponse
- On obtient une erreur
- On obtient
8 - On obtient
8.0 - On obtient
9.0