This Python script takes a single character input from the user, computes its ASCII value, and then displays both the character and its corresponding ASCII value.
character = input("Please enter character: ")
asciiValue = ord(character)
originalValue = chr(asciiValue)
print("ASCII value of the character " + repr(originalValue)
+ " is: " + repr(asciiValue))
Please enter character: c
ASCII value of the character 'c' is: 99
character = input("Please enter character: ")
input(...)
: Displays a message asking for user input and reads the entered character.asciiValue = ord(character)
ord(character)
: Returns the ASCII value of the provided character.originalValue = chr(asciiValue)
chr(asciiValue)
: Returns the character represented by the provided ASCII value.print("ASCII value of the character " + repr(originalValue)
+ " is: " + repr(asciiValue))
repr(originalValue)
: Converts the character to a string for printing.repr(asciiValue)
: Converts the ASCII value to a string for printing.