python program that finds the ASCII value of a given character:
character = input("Enter a character: ")
# Find the ASCII value of the character
value = ord(character)
print("The ASCII value of", character, "is", value)
The program prompts the user to enter a character using the input() function, and stores the value in the variable “character”. It then uses the built-in function ord()
to find the ASCII value of the character. The ord()
function returns an integer representing the Unicode character. At the end of the program, it prints the ASCII value of the character.
You can also use the format()
function to convert character to ASCII value:
character = input("Enter a character: ")
value = format(ord(character),"x")
print("The ASCII value of", character, "is", value)
The format()
function takes the ordinal value of the character and format it to hexadecimal representation, and the ‘x’ is used to format the value to hexadecimal representation.
Both methods will give you the same output which is the ASCII value of the entered character. You can use any method that suits your need or preference.