Python 官方文档:入门教程 => 点击学习
方法一(普通方法): # -*- coding: utf-8 -*- #把数字转换成相应的字符,1-->'A' 27-->'AA' def changeNumToChar(toSmallChar=None, to
方法一(普通方法):
# -*- coding: utf-8 -*-
#把数字转换成相应的字符,1-->'A' 27-->'AA'
def changeNumToChar(toSmallChar=None, toBiGChar=None):
#n = toSmallChar and toSmallChar or toBigChar
#c = toSmallChar and ord('A')-1 or ord('a')-1
init_number = 0
increment = 0
res_char = ''
if not toSmallChar and not toBigChar:
return ''
else:
if toSmallChar:
init_number = toSmallChar
increment = ord('A') - 1
else:
init_number = toBigChar
increment = ord('a') - 1
shang,yu = divmod(init_number, 26)
char = chr(yu + increment)
res_char = char*(shang + 1)
#for i in range(shang + 1):
# char = chr(yu + increment)
# res_char += char
return res_char
test_number = input()
result = changeNumToChar(toSmallChar=test_number)
print '%s对应的字符是:%s',test_number,result
def changeNumToChar(self, toSmallChar=None, toBigChar=None):
'''
把数字转换成相应的字符,1-->'A' 27-->'AA'
'''
init_number = 0
increment = 0
res_char = ''
if not toSmallChar and not toBigChar:
return ''
else:
if toSmallChar:
init_number = toSmallChar
increment = ord('a') - 1
else:
init_number = toBigChar
increment = ord('A') - 1
shang,yu = divmod(init_number, 26)
char = chr(yu + increment)
res_char = char * (shang + 1)
return res_char
--结束END--
本文标题: 用python把数字转换成字母
本文链接: https://lsjlt.com/news/192272.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0