Write A Python Program To Find ASCII Value Of Character

Given the character as an input to the Python program the program should get the ASCII value of the  given character and then print the ASCII value as output of the Python program.

Python provides an ord function to get the ASCII value of the given character,  let's use the ord() function call to get the ASCII value and print it as output.

 

Write A Python Program To Find ASCII Value Of Character

 


Write A Python Program To Find ASCII Value Of Character

Let's take a variable name as char to store the  input character from the user,  using the input function call to ask a user to enter a character and get the first value using index of [0].

char = input("Enter a character : ")[0]



 Once the user enters a character ,  take a new variable name as well you to show the ask the value of a given character  and call the ord() function call to convert the character to ASCII value.

value = ord(char)



Once the ord() function call gets executed,  the ASCII Value will be stored in the variable named as value.  use the print function call to print the ASCII value of the given character.

print(f"ASCII Value of Character {char} is : {value}")



Python Program
=============================

char = input("Enter a character : ")[0]

value = ord(char)

print(f"ASCII Value of Character {char} is : {value}")





Output
=============
Enter a character : c
ASCII Value of Character c is : 99



Output
=============
Enter a character : 8
ASCII Value of Character 8 is : 56



Output
============
Enter a character : B
ASCII Value of Character B is : 66




Output
=============
Enter a character : e
ASCII Value of Character e is : 101




Conclusion
===============
Execute the above Python program by providing random keyboard characters as input and then note down the ASCII values of each of the characters.

Comment it down Below if you have any suggestions to improve the about Python program





Post a Comment

0 Comments