Write a program to Find ASCII Value of Character in Python
Code:
1 2 3 4 5 6 7 8 | # Program to find the ASCII value of the given character #to take character from user c = input("Enter a character: ") print("The ASCII value of '" + c + "' is",ord(c)) |
This Python program takes a single character as input from the user and uses the built-in ord()
function to find the corresponding ASCII value of the character.
The program prompts the user to enter a character and assigns it to the variable c
. Then, it calls the ord()
function, passing in the character as an argument. The ord()
function returns an integer representing the ASCII value of the character.
Finally, the program prints out a string, concatenating the character and the ASCII value of that character using string formatting.
For example, if the user enters the character 'A'
, the output would be: