Exemplos
Uma lista Python compartilhada e depois 45 em binário e hexadecimal
Uma lista apontada por dois nomes, rastreada linha por linha ao lado do código, e depois um número convertido passo a passo.
- 2:25
- Problemas de programação
- Narrado por Erinome
- Inglês
Feito a partir de um 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. Transcrição do vídeo
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.
Mais exemplos
-
Como uma rede neural aprende Uma rede aprendendo a reconhecer gatos: um palpite, o erro que ela recebe e uma pequena correção, repetidos, sem uma única equação. 1:25 · Inglês -
Por que a Lua parece mudar de forma Escrito a partir de um artigo do NASA Space Place: a metade da Lua que o Sol sempre ilumina e as oito fases em ordem. 0:59 · Inglês -
Encontrando x em um quiz em árabe Uma questão de múltipla escolha com algarismos arábicos orientais, resolvida da direita para a esquerda com uma balança, com todas as alternativas na lousa e a certa circulada em verde. 1:07 · Árabe
Seu tema, desenhado em cerca de um minuto.
Seus primeiros 2 vídeos são grátis, de até 1 minuto cada, com marca d’água. Não precisa de cartão. Produto completo, com todas as vozes e estilos incluídos.