Last active
September 24, 2015 05:23
-
-
Save ohcrfpv/935d8e17eed79fa1ab13 to your computer and use it in GitHub Desktop.
python converter 10 to 26
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
''' | |
copyright: (c) 2015 by fewspider([email protected]). | |
~~~~~~~~~ | |
converter 10 to 26,like: | |
1 -> A | |
2 -> B | |
27 -> AA | |
~~~~~~~~~ | |
test it: | |
python base10to26.py 27 | |
''' | |
import sys | |
def base10to26(num): | |
converted_string, modstring = '', '' | |
currentnum = num | |
while currentnum: | |
mod = currentnum % 26 | |
mod = mod if mod != 0 else 26 | |
currentnum = (currentnum - mod) // 26 | |
converted_string = chr(64 + mod) + converted_string | |
return converted_string | |
if __name__ == '__main__': | |
num = int(sys.argv[1]) | |
rs = base10to26(num) | |
print 'num-----', num | |
print 'result------', rs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment