Размещено 3 года назад по предмету
Информатика
от dankochkurov
def convert_base(num, to_base=2, from_base=10):
# first convert to decimal number
n = int(num, from_base) if isinstance(num, str) else num
# now convert decimal to 'to_base' base
alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
res = ""
while n > 0:
n,m = divmod(n, to_base)
res += alphabet[m]
return res[::-1]
print(convert_base(12))
пожалуйста обьясните что делает код и обьясните каждую строчку