In this Tutorial -:

Understanding the Problem
In Python, each character is associated with a unique ASCII (American Standard Code for Information Interchange) value. ASCII is a character encoding standard used to represent text in computers and other devices. The ASCII value of a character is an integer that represents that character in the ASCII table.
In this tutorial, we’ll develop a Python program to print the ascii of a character entered by user.
Developing the Algorithm
-> Take user input for a character.
-> Convert the character to its ASCII value using the built-in ord() function in Python.
-> Display the ASCII value to the user.
Writing the Python Code
# Function to print ASCII value of a character
def print_ascii_value(character):
ascii_value = ord(character)
print(f"ASCII value of '{character}' is {ascii_value}")
# Main function
def main():
# Input a character
character = input("Enter a character: ")
# Print ASCII value of the character
print_ascii_value(character)
if __name__ == "__main__":
main()
O/P
Enter a character: A
ASCII value of ‘A’ is 65
Time Complexity
The time complexity of this program is constant (O(1)) because the execution time is not dependent on the character entered. The program will always execute a fixed number of operations regardless of the character.
Code Explanation
We define a function print_ascii_value that takes a character as an argument.
Inside the function, we use the ord() function to convert the character to its ASCII value and store it in the ascii_value variable.
The main function is defined to take user input for a character.
The print_ascii_value function is called with the user-provided character, and the ASCII value is printed to the user.
Dry Run
Let’s perform a dry run of the program with the following input:
-> Character = ‘A’
Execution:
-> User enters a character: ‘A’
-> The print_ascii_value function is called with character = ‘A’.
-> The ASCII value of ‘A’ is calculated using the ord() function, which returns 65 (ASCII value of ‘A’).
-> The program prints “ASCII value of ‘A’ is 65”.
The program successfully converts the entered character to its ASCII value and displays it to the user.
