Advertisement
JPablos

Cambio de base. Python

Apr 2nd, 2021 (edited)
751
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. """
  4. Este código permite generar una tabla a partir de un rango de decimales
  5. para convertirlos a diferentes bases.
  6.  
  7.        Convenciones:
  8.                        Decimal (base 10)       --> 0d
  9.                        Hexadecimal(base 16)    --> 0x
  10.                        Octal (base 8)          --> 0o
  11.                        Binario (base 2)        --> 0b
  12. """
  13.  
  14. # pylint: disable=consider-using-f-string
  15.  
  16. print(
  17.     "{0:>8s} {1:>9s} {2:>9s} {3:>9s}".format("0d", "0x", "0o", "0b"),
  18.     "\n",
  19.     (chr(8212)) * 39,
  20. )
  21.  
  22.  
  23. for num in range(1, 32):
  24.     for base in "dXob":
  25.         print("{0:{width}{base}}".format(num, base=base, width=8), end=" |")
  26.     print()
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement