Python Programs | IT Developer
IT Developer

Python Programs



Share with a Friend

Python Programs - Input and Output

Input a character and print its ASCII code - Python Program

# Prompt the user to enter a character ch = input("Enter a character: ") # Check if the input is a single character if len(ch) == 1: # Get the ASCII value using ord() ascii_value = ord(ch) # Print the character and its ASCII value print(f"The ASCII value of '{ch}' is {ascii_value}") else: print("Invalid input: Please enter a single character.")

Output

 
OUTPUT  1:
Enter a character: a
The ASCII value of 'a' is 97

OUTPUT  2:
Enter a character: A
The ASCII value of 'A' is 65

OUTPUT  3:
Enter a character: $
The ASCII value of '$' is 36

OUTPUT  4:
Enter a character: hello
Invalid input: Please enter a single character.