Hi everyone I was just exploring through ASCII in python. But the thing is i cannot find the ASCII value by each letter of the entered value With its corresponding letter. I was just able to find ASCII with number only. Suppose let me just ask how do i get the result in the following way. A program that ask the user to enter their first name. The program then prints each letter of the user’s first name along with the corresponding ASCII value. Suppose the entered value is TAN than the output should be like below. T 116 A 97 N 110
Asked
Active
Viewed 3,711 times
0
-
1The function you are looking for is called [`ord`](https://docs.python.org/3/library/functions.html#ord). If you need more help then you will need to try to write a little code and ask a more specific question. – Karl Knechtel May 15 '20 at 03:21
-
1Does 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) – Abhishek Prusty May 15 '20 at 03:51
4 Answers
1
In order to find the ASCII value of a character use the builtin function ord
and in order to get the charecter from the value use chr
ord("a")
would give you 97 and
chr(97)
would give you 'a'

Omri Bahat Treidel
- 528
- 4
- 11
0
This works for me:
>>> import string
>>> string.ascii_letters
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
>>> for ch in string.ascii_letters :
... print ch, ord(ch),
...
a 97 b 98 c 99 d 100 e 101 f 102 g 103 h 104 i 105 j 106 k 107 l 108 m 109 n 110 o 111 p 112 q 113 r 114 s 115 t 116 u 117 v 118 w 119 x 120 y 121 z 122 A 65 B 66 C 67 D 68 E 69 F 70 G 71 H 72 I 73 J 74 K 75 L 76 M 77 N 78 O 79 P 80 Q 81 R 82 S 83 T 84 U 85 V 86 W 87 X 88 Y 89 Z 90
>>>

lenik
- 23,228
- 4
- 34
- 43
0
You could use ord()
to do so. Here is the code that would do so:
name = input()
#name = "TAN"
for i in name:
print(i, end = " ")
print(ord(i), end = " ")
Output:
T 116 A 97 N 110

Rishit Dagli
- 1,000
- 8
- 20
-
Taking input is very easy so I did not write code for that, however, I will edit it – Rishit Dagli May 15 '20 at 03:43
0
You could use ord() function.
s = input("Enter your name : ")
for char in s:
print(f"{char} {ord(char)}", end="\t")
Output
Enter your name : Albus Percival Wulfric Brian Dumbledore
A 65 l 108 b 98 u 117 s 115 32 P 80 e 101 r 114 c 99 i 105 v 118 a 97 l 108 32 W 87 u 117 l 108 f 102 r 114 i 105 c 99 32 B 66 r 114 i 105 a 97 n 110 32 D 68 u 117 m 109 b 98 l 108 e 101 d 100 o 111 r 114 e 101

Abhishek Prusty
- 862
- 9
- 15