Answer to Question #311053 in Python for Ram

Question #311053

write a program to generate a sequence and print the corresponding value of a key for the given string a key.


Input


A,AA,AB,AAA


OUTPUT


1,27,53,703




1
Expert's answer
2022-03-14T17:58:49-0400
def convert(s):
    n = len(s)
    res = 0
    for i in range(n-1, -1, -1):
        res *= 26
        res += ord(s[i]) - ord('A') + 1
    return res


def main():
    line = input()
    L = [str(convert(s)) for s in line.split(',')]
    res =','.join(L)
    print(res)


main()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS