Search code examples
pythonletter

How do I convert letters to their corresponding number value?


I am relatively new to python. As a mini-project, I am creating a program that involves taking one-word two strings and converting each character to their corresponding letter value (e.g A = 1, C = 3, Z = 26). I want to find a way to do this without assigning all 26 letters to a number in a dictionary. Every algorithm I have found online doesn't seem to be working or I don't understand it.

I am completely lost on how to go about this. I would appreciate it if someone could point me in the right direction.

Thanks


Solution

  • for example...

    letter = 'c'
    print(ord(letter)-96)