In this article, we will learn about python program to print Alphabet for given ASCII value.
Getting Started
Our task is to print a character for given ASCII value. For example,
If user enters a, output should be – 97
If use enters z, output should be – 122
If use enters A, output should be – 65
If use enters B, output should be – 66
and so on …
We can do so using chr() function in python.
Print Character for Given ASCII Value using chr()
We can use chr() function in python and do above task as shown below –
ch = input("Enter a valid ASCII Value") chInt = int(ch) print("ASCII Value: " + ch + ", Character: ", chr(chInt))
Output:
Enter a valid ASCII Value 90 ASCII Value: 90, Character: Z
In above program,
- input() function accepts value entered by user and store it in variable ch.
- Since value returned by input() function is string, we need to convert it into int because chr() function accepts integer value. Stored the converted int value in variable chInt
- Then, we print corresponding character using chr() and print() function.
That’s how we can write python program to print alphabet for given ASCII value with examples.
Reference: Official Doc