So have it map from the remainders to the index of your characters.
import string def numberToBase(n, b): if n == 0: return [0] digits = [] while n: digits.append(int(n % b)) n //= b return digits[::-1] indexes = numberToBase(1984, 27) print(indexes) characters = string.digits + string.ascii_uppercase output = "".join(characters[x] for x in indexes) print(output)
Output:[2, 19, 13]
2JD