Actually, the whole question in the title. The function itself is needed to solve the problem. The essence of the problem is that they introduce the number and bases of its number system, and it is necessary to check that the number fits the base, i.e. each digit (or lat. letter) is less than the base.
My algorithm is to convert the number to decimal, and then from the 10th it is not difficult to check, for the 10th code I have already written:
while a % 10 <= n and a != 0: a //= 10 if a == 0: print('YES') else: print('NO')