Lesnic

gr2_lesson2_task1

Sep 18th, 2021
564
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.     for i in n[::-1]:
  4.         if '0' <= i <= '9':
  5.             temp += int(i) * now
  6.         else:
  7.             temp += (ord(i) - ord('A') + 10) * now
  8.         now *= base1
  9.  
  10.     n = ''
  11.     while temp != 0:
  12.         now = temp % base2
  13.         if now < 10:
  14.             n += str(now)
  15.         else:
  16.             n += chr(now - 10 + ord('A'))
  17.         temp //= base2
  18.     print(n[::-1])
RAW Paste Data