You can shoot something like
string.ascii_lowercase.index(message[2])
Which returns 13. You are missing ascii_ .
This will work (as long as the message is lowercase), but it includes a linear alphabetical search, as well as module import.
Instead, just use
ord(message[2]) - ord('a')
Alternatively, you can use
ord(message[2].lower()) - ord('a')
if you want this to work if some letters in message are uppercase.
If you want, for example, rank a should be 1, not 0, use
1 + ord(message[2].lower()) - ord('a')
source share