code: def bx_encode(n, alphabet):
     
   
     if not isinstance(n, int):
        raise TypeError('an integer is required')
  
     base = len(alphabet)
  
     if n == 0:
        return alphabet[0]
  
     digits = []
     
     while n > 0:
        digits.append(alphabet[n % base])
        n = n // base
     
     digits.reverse()
     return ''.join(digits)
docs: \
     Encodes an integer :attr:`n` in base ``len(alphabet)`` with 
     digits in :attr:`alphabet`.
   
     ::
  
        # 'ba'
        bx_encode(3, 'abc')
  
     :param n:            a positive integer.
     :param alphabet:     a 0-based iterable.