Advertisement
Guest User

walex

a guest
Jun 15th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.21 KB | None | 0 0
  1. n = int(input('digite o numero que deseja:\n'))
  2. n1 = int(input('1 = binario\n2 = octal\n3 = hexadecimal\n4 = octal P/decimal\n'))
  3. total = int(0)
  4. totalteste = int(0)
  5. expoente = int(0)
  6. total1 = str()
  7. lista = []
  8. if n1 == 1:
  9.     while True:
  10.         if n >= 2:
  11.             total = n % 2
  12.             lista = lista + [total]
  13.             n = n // 2
  14.         if n <= 1:
  15.             total = n % 2
  16.             lista = lista + [total]
  17.             print(lista[::-1])
  18.             break
  19. if n1 == 2:
  20.     while True:
  21.         if n >= 8:
  22.             total = n % 8
  23.             lista = lista + [total]
  24.             n = n // 8
  25.         if n <= 7:
  26.             total = n % 8
  27.             lista = lista + [total]
  28.             print(lista[::-1])
  29.             break
  30. if n1 == 3:
  31.     while True:
  32.         if n >= 16:
  33.             total = n % 16
  34.             if total == 10:
  35.                 total1 = 'A'
  36.             elif total == 11:
  37.                 total1 = 'B'
  38.             elif total == 12:
  39.                 total1 = 'C'
  40.             elif total == 13:
  41.                 total1 = 'D'
  42.             elif total == 14:
  43.                 total1 = 'E'
  44.             elif total == 15:
  45.                 total1 = 'F'
  46.             else:
  47.                 total1 = total
  48.             lista = lista + [total1]
  49.             n = n // 16
  50.         if n <= 15:
  51.             total = n % 16
  52.             total1 = total
  53.             if total == 10:
  54.                 total1 = 'A'
  55.             elif total == 11:
  56.                 total1 = 'B'
  57.             elif total == 12:
  58.                 total1 = 'C'
  59.             elif total == 13:
  60.                 total1 = 'D'
  61.             elif total == 14:
  62.                 total1 = 'E'
  63.             elif total == 15:
  64.                 total1 = 'F'
  65.             else:
  66.                 total1 = total
  67.             lista = lista + [total1]
  68.             print(lista[::-1])
  69.             break
  70. if n1 == 4:
  71.         while True:
  72.             if n >= 10:
  73.                 total = n % 10
  74.                 totalteste += total * (8**expoente)
  75.                 n = n // 10
  76.             elif n <= 9:
  77.                 total = n % 10
  78.                 totalteste += total * (8**expoente)
  79.                 print(totalteste)
  80.                 break
  81.             expoente += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement