#coding: utf-8 import math def translate(num,base_num): if num < base_num: return str(num) else: n = int(math.log10(num)/math.log10(base_num))+1 trans_num = '' for i in range(n): num_add = num/(base_num**(n-i-1)) trans_num = trans_num + str(num_add) num = num - num_add*(base_num**(n-i-1)) return trans_num if __name__ == '__main__': print translate(100,2) print translate(100,8) print translate(100,5)