用Python语句怎么写啊?
发布网友
发布时间:2022-03-03 23:02
我来回答
共1个回答
热心网友
时间:2022-03-04 00:31
#未对输入参数进行检查,有必要可自行完善
import string
ls = list(string.ascii_uppercase)
def ts2d(s):
sl = len(s)
result = 0
for i in range(sl):
result += (ls.index(s[ i ]) + 1) * 26 ** (sl - i - 1)
return result
print(ts2d('ABC'))
def d2ts(num):
result = ''
while num > 26:
s = num % 26
result += ls[ s - 1 ]
num //= 26
return (result + ls[ num - 1 ])[ ::-1 ]
print(d2ts(731))