Peter is making a new dictionary
Input:42
Output:AP
# 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()
Comments
Leave a comment