10进制转换36进制

def transform36(n):
    res = []
    while n:
        res.append(n%36)
        n = n//36
    out = []
    for rr in res[::-1]:
        if 0 <= rr <= 9:
            out.append(str(rr))
        else:
            out.append(chr(rr +ord('a')-10))
    return ''.join(out)

# 简单测试一下
print(transform36(int(36 * 35)))  # z0

 

posted @ 2023-07-01 18:46  乐乐章  阅读(78)  评论(0编辑  收藏  举报