• Study Materials
    • InfyTQ Archive
    • Infosys Archive
    • TCS Archive
    • Accenture Archive
    • AMCAT Archive
    • Capgemini Archive
    • Cisco Archive
    • CoCubes Archive
    • Cognizant(CTS) Archive
    • Deloitte Archive
    • DXC Archive
    • Goldman Sachs Archive
    • Hexaware Technologies Archive
    • LTI Archive
    • MindTree Archive
    • Virtusa Archive
    • Wipro Archive
  • Interview Preparation
    • C Interview Questions
    • Data Structures Interview Questions
    • DBMS Interview Questions
    • HR Interview Questions
    • Java Interview Questions
    • Operating System Interview Questions
    • Python Interview Questions
    • SQL Query Interview Questions
  • Tutorials
    • Node.js Tutorial
    • Express.js Tutorial
    • Python Tutorial
  • Programming
    • C Programming MCQs
    • C Code Snippets – Output Questions
    • Python Code Snippets – Output Questions
    • Java Code Snippets – Output Questions
  • Aptitude
    • Verbal Ability for Placements
CODE OF GEEKS

We at CODE OF GEEKS, aim at providing best and quality content for our users at no extra cost.

    • Study Materials
      • InfyTQ Archive
      • Infosys Archive
      • TCS Archive
      • Accenture Archive
      • AMCAT Archive
      • Capgemini Archive
      • Cisco Archive
      • CoCubes Archive
      • Cognizant(CTS) Archive
      • Deloitte Archive
      • DXC Archive
      • Goldman Sachs Archive
      • Hexaware Technologies Archive
      • LTI Archive
      • MindTree Archive
      • Virtusa Archive
      • Wipro Archive
    • Interview Preparation
      • C Interview Questions
      • Data Structures Interview Questions
      • DBMS Interview Questions
      • HR Interview Questions
      • Java Interview Questions
      • Operating System Interview Questions
      • Python Interview Questions
      • SQL Query Interview Questions
    • Tutorials
      • Node.js Tutorial
      • Express.js Tutorial
      • Python Tutorial
    • Programming
      • C Programming MCQs
      • C Code Snippets – Output Questions
      • Python Code Snippets – Output Questions
      • Java Code Snippets – Output Questions
    • Aptitude
      • Verbal Ability for Placements
CODE OF GEEKS
CODE OF GEEKS
  • Study Materials
    • InfyTQ Archive
    • Infosys Archive
    • TCS Archive
    • Accenture Archive
    • AMCAT Archive
    • Capgemini Archive
    • Cisco Archive
    • CoCubes Archive
    • Cognizant(CTS) Archive
    • Deloitte Archive
    • DXC Archive
    • Goldman Sachs Archive
    • Hexaware Technologies Archive
    • LTI Archive
    • MindTree Archive
    • Virtusa Archive
    • Wipro Archive
  • Interview Preparation
    • C Interview Questions
    • Data Structures Interview Questions
    • DBMS Interview Questions
    • HR Interview Questions
    • Java Interview Questions
    • Operating System Interview Questions
    • Python Interview Questions
    • SQL Query Interview Questions
  • Tutorials
    • Node.js Tutorial
    • Express.js Tutorial
    • Python Tutorial
  • Programming
    • C Programming MCQs
    • C Code Snippets – Output Questions
    • Python Code Snippets – Output Questions
    • Java Code Snippets – Output Questions
  • Aptitude
    • Verbal Ability for Placements

Python Program to Print ASCII Value of a Character

  • July 29, 2023
  • CODE OF GEEKS
  • 0
In this Tutorial -:
  • Understanding the Problem
  • Developing the Algorithm
  • Writing the Python Code
  • Time Complexity
  • Code Explanation
  • Dry Run
Python Program to Print ASCII Value of a Character

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.





Tags: ASCII value conversion in PythonHow to print ASCII value of a character in PythonPython code to find ASCII value of a characterPython function for ASCII value retrievalPython ord() function tutorialPython program for ASCII value calculationPython program to display ASCII code of a characterPython script to get ASCII value of a characterStep-by-step guide to find ASCII value in PythonUnderstanding ASCII values in Python
  • Previous Embarking on a Go-rgeous Journey: An Introduction to Go Programming Language
  • Next Python Program to Find the Area of a Circle

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Advertise with us

Python Tutorial

NodeJS Tutorial

Express.JS Tutorial

Study Materials : Company Wise

Verbal Ability for Placements

CODE OF GEEKS

Subscribe to Newsletter

CODE OF GEEKS

Learn | Code | Achieve

Reach us

[email protected]
We at CODE OF GEEKS, aim at providing quality content to our users at no cost.
CODE OF GEEKS

Important Pages

About us
Advertise
Privacy Policy
Terms and Conditions
Refund Policy
Contact us

Placements – Study Materials

TCS NQT     Wipro     CapGemini
Accenture     MindTree     CTS
DXC     Hexaware Technologies     AMCAT
CoCubes     Goldman Sachs     Dell
Cisco     Deloitte     Virtusa     LTI     Infosys   

Tutorials

Python
Node.js
Express.js
Golang

Recent Posts

Strings in Go and its basic operations
  • August 11, 2023
Introduction to Functions in Go programming
  • August 11, 2023

Copyright @ CODE OF GEEKS. All Rights Reserved.