Answer to Question #292078 in Python for AkP

Question #292078

Peter is making a new dictionary




Input:42




Output:AP

1
Expert's answer
2022-01-30T07:24:08-0500
# Python 3.9.5

import string


def Getletterfromindex(num):
    num2alphadict = dict(zip(range(1, 27), string.ascii_uppercase))
    outval = ""
    numloops = (num - 1) // 26

    if numloops > 0:
        outval = outval + Getletterfromindex(numloops)

    remainder = num % 26
    if remainder > 0:
        outval = outval + num2alphadict[remainder]
    else:
        outval = outval + "Z"
    return outval


def main():
    number = int(input('Enter number: '))
    print(Getletterfromindex(number))


if __name__ == '__main__':
    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