Lesnic

gr1_lesson2_task1

Sep 18th, 2021
542
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def n1(n, base1, base2):
  2.     temp, now = 0, 1
  3.  
  4.     for i in n[::-1]:
  5.         if '0' <= i <= '9':
  6.             temp += int(i) * now
  7.         else:
  8.             temp += (ord(i) - ord('A') + 10) * now
  9.         now *= base1
  10.     print(temp)
  11.     n = ''
  12.     while temp != 0:
  13.         now = temp % base2
  14.         if now < 10:
  15.             n += str(now)
  16.         else:
  17.             n += chr(now - 10 + ord('A'))
  18.         temp //= base2
  19.     print(n[::-1])
RAW Paste Data