Jan-20-2024, 03:47 AM
(This post was last modified: Jan-20-2024, 03:47 AM by deanhystad.)
Your message is suspect. When I run this code:
It would be nice if you provided proof of this:
This did not happen:
I would not use index for something like this. I would use a dictionary.
Output:from string import ascii_lowercase
alpha_char = input("Enter a letter of the English alphabet: ")
index_num = ascii_lowercase.index(alpha_char)
print(index_num)
If I enter something that is not a lower case ascii character, I get this message:Error:ValueError: substring not found
Not the same error message.It would be nice if you provided proof of this:
Quote:I know that the input process worked, because I used a print statement right before the error line, and I got the user input correctly printed.Your posted code contains no print commands. You should post the code you are running. The code you have posted runs correctly as far as I can tell.
This did not happen:
Quote:Somehow, trying to use a variable as the index element seems to have converted it to a space or a null character (I think).There is an error in your code that you did not post. If you post the code that has this behavior, we can help you understand what is happening.
I would not use index for something like this. I would use a dictionary.
from string import ascii_lowercase # Make dictionary mapping characters to their index alphabet_list = {letter: index for index, letter in enumerate(ascii_lowercase)} alpha_char = input("Enter a letter of the English alphabet: ") index_num = alphabet_list.get(alpha_char, None) print(index_num)