-3

How would one write a code to display the conversion of individual letters in a string to it's ASCII equivalent? One example of the output in shell would look like this:

Enter a 3-letter word: Hey
H = 72
e = 101
y = 121
James
  • 1
  • 1
  • 3
    Does this answer your question? [How to get the ASCII value of a character](https://stackoverflow.com/questions/227459/how-to-get-the-ascii-value-of-a-character) – kaya3 Feb 05 '20 at 19:02
  • You can use `ord` to get ascii equivalent of the character. And `chr` to convert ascii value to character. – Ch3steR Feb 05 '20 at 19:02

2 Answers2

0

Use built-in ord function

>>> ord('H')
72
LinnTroll
  • 705
  • 4
  • 10
0

Get the input, and print each character plus its ordinal value.

user_input = input("Enter a 3-letter word: ")
for character in user_input:
    print(character + " = " + ord(character))
Michael Bianconi
  • 5,072
  • 1
  • 10
  • 25