fork download
  1. def convBin():
  2. cont = []
  3. rest = []
  4. dev = []
  5. decimal = []
  6.  
  7. print("Ingrese el valor a convertir: ")
  8. valor = 18.5
  9.  
  10. if isinstance(valor, int):
  11. while valor > 0:
  12. z = valor // 2
  13. print ("z", z)
  14. resto = valor%2
  15. valor = valor // 2
  16. cont.append(z)
  17. rest.append(resto)
  18.  
  19. cont.reverse()
  20. rest.reverse()
  21.  
  22. dev.append(cont[0])
  23.  
  24. x = 0
  25. while x <= (len(rest) - 1):
  26. dev.append(rest[x])
  27. x += 1
  28.  
  29. print(" ")
  30. print("Lista de devoluciones: ")
  31. print(dev)
  32. print("")
  33.  
  34. elif isinstance(valor, float):
  35. a = valor // 1
  36. b = valor % 1
  37.  
  38. while a > 0:
  39. z = a // 2
  40. resto = a%2
  41. a = a // 2
  42. cont.append(z)
  43. rest.append(resto)
  44.  
  45. cont.reverse()
  46. rest.pop()
  47.  
  48. dev.append(cont[1])
  49.  
  50. for i in rest:
  51. dev.append(rest[i])
  52.  
  53. print("Inserte el número de error minimo")
  54. num = input()
  55.  
  56. while num > 0:
  57. dec = b * 1
  58. dec2 = dec//1
  59. dec %= 1
  60. decimal.append(dec2)
  61.  
  62. print("Parte entera: ")
  63. print(dev)
  64. print("Parte decimal:")
  65. print(num)
  66.  
  67. else:
  68. print("Ha aparecido un error")
  69.  
  70.  
  71. convBin()
Runtime error #stdin #stdout #stderr 0.02s 27704KB
stdin
Standard input is empty
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