Exemples
Une liste Python partagée, puis 45 en binaire et en hexadécimal
Une liste désignée par deux noms, suivie ligne par ligne à côté du code, puis un nombre converti étape par étape.
- 2:25
- Problèmes de code
- Narrée par Erinome
- Anglais
Créée à partir d’un prompt
Trace these for my class. 1) What is the output?
x = [1, 2, 3]
y = x
y.append(4)
print(len(x))
2) Convert 45 to binary, then to hexadecimal. Transcription de la vidéo
In this video, we trace a Python list and convert a decimal number to binary and hexadecimal.
Question one. What is the output?
First, x equals a list containing one, two, and three.
Next, y equals x, so both names refer to the same list. The call y dot append with four adds four to that shared list. Now x and y both refer to the list containing one, two, three, and four.
The print call evaluates len of x, which is four.
Notice that assigning y equals x does not copy the list. Hence, the output is four.
Question two. Convert forty-five to binary, then to hexadecimal.
First, repeatedly divide forty-five by two, keeping each remainder. Forty-five divided by two gives twenty-two with remainder one.
Twenty-two divided by two gives eleven with remainder zero.
Eleven divided by two gives five with remainder one.
Five divided by two gives two with remainder one.
Two divided by two gives one with remainder zero.
One divided by two gives zero with remainder one.
Reading the remainders from bottom to top gives one zero one one zero one in binary. For hexadecimal, divide forty-five by sixteen to get two with remainder thirteen.
Then divide two by sixteen to get zero with remainder two.
In hexadecimal, thirteen is written as D. Reading those remainders from bottom to top gives two D. As a check, two times sixteen plus thirteen equals forty-five.
Hence, forty-five is one zero one one zero one in binary and two D in hexadecimal.
Plus d’exemples
-
Comment un réseau de neurones apprend Un réseau qui apprend à reconnaître des chats : une supposition, l’erreur qu’on lui renvoie et une petite correction, répétées, sans une seule équation. 1:25 · Anglais -
Pourquoi la Lune semble changer de forme Écrit d’après un article de NASA Space Place : la moitié de la Lune que le Soleil éclaire toujours, et les huit phases dans l’ordre. 0:59 · Anglais -
Trouver x, dans un quiz en arabe Une question à choix multiples en chiffres arabes orientaux, résolue de droite à gauche avec une balance, tous les choix au tableau et la bonne réponse entourée en vert. 1:07 · Arabe
Votre sujet, dessiné en une minute environ.
Vos 2 premières vidéos sont gratuites, jusqu’à 1 minute chacune, avec filigrane. Sans carte bancaire. Tout le produit, toutes les voix et tous les styles compris.