def convBin( ) :
cont = [ ]
rest = [ ]
dev = [ ]
decimal = [ ]
print ( "Ingrese el valor a convertir: " )
valor = 18.5
if isinstance ( valor, int ) :
while valor > 0 :
z = valor // 2
print ( "z" , z)
resto = valor%2
valor = valor // 2
cont.append ( z)
rest.append ( resto)
cont.reverse ( )
rest.reverse ( )
dev.append ( cont[ 0 ] )
x = 0
while x <= ( len ( rest) - 1 ) :
dev.append ( rest[ x] )
x += 1
print ( " " )
print ( "Lista de devoluciones: " )
print ( dev)
print ( "" )
elif isinstance ( valor, float ) :
a = valor // 1
b = valor % 1
while a > 0 :
z = a // 2
resto = a%2
a = a // 2
cont.append ( z)
rest.append ( resto)
cont.reverse ( )
rest.pop ( )
dev.append ( cont[ 1 ] )
for i in rest:
dev.append ( rest[ i] )
print ( "Inserte el número de error minimo" )
num = input ( )
while num > 0 :
dec = b * 1
dec2 = dec//1
dec %= 1
decimal .append ( dec2)
print ( "Parte entera: " )
print ( dev)
print ( "Parte decimal:" )
print ( num)
else :
print ( "Ha aparecido un error" )
convBin( )
ZGVmIGNvbnZCaW4oKToKICAgIGNvbnQgPSBbXQogICAgcmVzdCA9IFtdCiAgICBkZXYgPSBbXQogICAgZGVjaW1hbCA9IFtdCgogICAgcHJpbnQoIkluZ3Jlc2UgZWwgdmFsb3IgYSBjb252ZXJ0aXI6ICIpCiAgICB2YWxvciA9IDE4LjUKCiAgICBpZiBpc2luc3RhbmNlKHZhbG9yLCBpbnQpOgogICAgICAgIHdoaWxlIHZhbG9yID4gMDoKICAgICAgICAgICAgeiA9IHZhbG9yIC8vIDIKICAgICAgICAgICAgcHJpbnQgKCJ6IiwgeikKICAgICAgICAgICAgcmVzdG8gPSB2YWxvciUyCiAgICAgICAgICAgIHZhbG9yID0gdmFsb3IgLy8gMgogICAgICAgICAgICBjb250LmFwcGVuZCh6KQogICAgICAgICAgICByZXN0LmFwcGVuZChyZXN0bykKCiAgICAgICAgY29udC5yZXZlcnNlKCkKICAgICAgICByZXN0LnJldmVyc2UoKQoKICAgICAgICBkZXYuYXBwZW5kKGNvbnRbMF0pCgogICAgICAgIHggPSAwCiAgICAgICAgd2hpbGUgeCA8PSAobGVuKHJlc3QpIC0gMSk6CiAgICAgICAgICAgIGRldi5hcHBlbmQocmVzdFt4XSkKICAgICAgICAgICAgeCArPSAxCgogICAgICAgIHByaW50KCIgIikKICAgICAgICBwcmludCgiTGlzdGEgZGUgZGV2b2x1Y2lvbmVzOiAiKQogICAgICAgIHByaW50KGRldikKICAgICAgICBwcmludCgiIikKCiAgICBlbGlmIGlzaW5zdGFuY2UodmFsb3IsIGZsb2F0KToKICAgICAgICBhID0gdmFsb3IgLy8gMQogICAgICAgIGIgPSB2YWxvciAlIDEKCiAgICAgICAgd2hpbGUgYSA+IDA6CiAgICAgICAgICAgIHogPSBhIC8vIDIKICAgICAgICAgICAgcmVzdG8gPSBhJTIKICAgICAgICAgICAgYSA9IGEgLy8gMgogICAgICAgICAgICBjb250LmFwcGVuZCh6KQogICAgICAgICAgICByZXN0LmFwcGVuZChyZXN0bykKCiAgICAgICAgY29udC5yZXZlcnNlKCkKICAgICAgICByZXN0LnBvcCgpCgogICAgICAgIGRldi5hcHBlbmQoY29udFsxXSkKCiAgICAgICAgZm9yIGkgaW4gcmVzdDoKICAgICAgICAgICAgZGV2LmFwcGVuZChyZXN0W2ldKQoKICAgICAgICBwcmludCgiSW5zZXJ0ZSBlbCBuw7ptZXJvIGRlIGVycm9yIG1pbmltbyIpCiAgICAgICAgbnVtID0gaW5wdXQoKQoKICAgICAgICB3aGlsZSBudW0gPiAwOgogICAgICAgICAgICBkZWMgPSBiICogMQogICAgICAgICAgICBkZWMyID0gZGVjLy8xCiAgICAgICAgICAgIGRlYyAlPSAxICAgICAgICAKICAgICAgICAgICAgZGVjaW1hbC5hcHBlbmQoZGVjMikKCiAgICAgICAgcHJpbnQoIlBhcnRlIGVudGVyYTogIikKICAgICAgICBwcmludChkZXYpCiAgICAgICAgcHJpbnQoIlBhcnRlIGRlY2ltYWw6IikKICAgICAgICBwcmludChudW0pCgogICAgZWxzZToKICAgICAgICBwcmludCgiSGEgYXBhcmVjaWRvIHVuIGVycm9yIikKICAgICAgICAKICAgICAgICAKY29udkJpbigp
stdout
Ingrese el valor a convertir:
stderr
Traceback (most recent call last):
File "./prog.py", line 71, in <module>
File "./prog.py", line 51, in convBin
TypeError: list indices must be integers or slices, not float