Function that turns numbers into letters and vice versa (this got deleted for some reason) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Function that turns numbers into letters and vice versa (this got deleted for some reason)

It is intended to implement two auxiliary functions that allow us to convert letters into numbers and vice versa. They will be helpful in some of the following questions. Define the functions “char2idx” and “idx2char” whose purpose is, respectively, to convert letters to numbers and numbers to letters. We assume that 'A' is zero, 'B' is 1, and so on, until the letter 'Z' is 25.

5th Jan 2022, 5:32 PM
João Joana
2 Answers
5th Jan 2022, 7:57 PM
FanYu
FanYu - avatar
0
char2idx: Use the ord() function to get the ASCII value of the letter. Subtract 65 from the ASCII value to so that A (65) will be 0, B (66) will be 1, and so on. idx2char: Use the chr () function to convert the calculated char value into a string. Calculate the character value by reversing the above.
6th Jan 2022, 11:30 PM
Brian
Brian - avatar