Tutorialspoint
Problem
Solution
Submissions

Print the ASCII Value of a Character

Certification: Basic Level Accuracy: 94.74% Submissions: 95 Points: 5

Write a Python program that prints the ASCII value of a given character.

Example 1
  • Input: character = 'A'
  • Output: 65
  • Explanation:
    • Step 1: Take the character 'A' as input.
    • Step 2: Use the ord() function to get the ASCII value.
    • Step 3: Print the ASCII value 65.
Example 2
  • Input: character = 'a'
  • Output: 97
  • Explanation:
    • Step 1: Take the character 'a' as input.
    • Step 2: Use the ord() function to get the ASCII value.
    • Step 3: Print the ASCII value 97.
Constraints
  • Input is a single valid ASCII character
  • Time Complexity: O(1)
  • Space Complexity: O(1)
Control StructuresFunctions / MethodsBitwise OperationsFacebookCapgemini
Editorial

Login to view the detailed solution and explanation for this problem.

My Submissions
All Solutions
Lang Status Date Code
You do not have any submissions for this problem.
User Lang Status Date Code
No submissions found.

Please Login to continue
Solve Problems

 
 
 
Output Window

Don't have an account? Register

Solution Hints

  • Use ord() function: ascii_value = ord(char)
  • Check if input is a single character: if len(char) == 1: ascii_value = ord(char)
  • Handle exceptions: try: ascii_value = ord(char) except TypeError: print("Input should be a character")

The following are the steps to print the ASCII value of a character:

  • Take a single character as input.
  • Use the `ord()` function to get the ASCII value.
  • Store the value in a variable.
  • Print the ASCII value.
  • Verify with uppercase, lowercase, and special characters.

Submitted Code :