;

Python Program to Find the ASCII Value of Total Characters in a String


Tutorialsrack 22/04/2020 Python

In the Python program, we will learn how to find the ASCII value of the total characters in a string. In this program, we will use ord() function to convert the character to the ASCII value and print it and for iterating the string, we will use for loop and while loop.

Here is the code of the program to find the ASCII value of total characters in a string.

Program 1: Python Program to Find the ASCII Value of Total Characters in a String using FOR Loop

Python Program to Find the ASCII Value of Total Characters in a String using FOR Loop

# Python Program to Find the ASCII Value of Total Characters in a String using FOR Loop

# Take the Input From the User
myStr = input("Enter the String: ")
 
for i in range(len(myStr)):
    print("The ASCII Value of Character %c = %d" %(myStr[i], ord(myStr[i])))
Output

Enter the String: Tutorialsrack

The ASCII Value of Character T = 84

The ASCII Value of Character u = 117

The ASCII Value of Character t = 116

The ASCII Value of Character o = 111

The ASCII Value of Character r = 114

The ASCII Value of Character i = 105

The ASCII Value of Character a = 97

The ASCII Value of Character l = 108

The ASCII Value of Character s = 115

The ASCII Value of Character r = 114

The ASCII Value of Character a = 97

The ASCII Value of Character c = 99

The ASCII Value of Character k = 107

Program 2: Python Program to Find the ASCII Value of Total Characters in a String using WHILE Loop

Python Program to Find the ASCII Value of Total Characters in a String using WHILE Loop

# Python Program to Find the ASCII Value of Total Characters in a String using WHILE Loop

# Take the Input From the User
myStr = input("Enter the String: ")

i = 0

while(i < len(myStr)):
    print("The ASCII Value of Character %c = %d" %(myStr[i], ord(myStr[i])))
    i = i + 1
Output

Enter the String: Tutorialsrack

The ASCII Value of Character T = 84

The ASCII Value of Character u = 117

The ASCII Value of Character t = 116

The ASCII Value of Character o = 111

The ASCII Value of Character r = 114

The ASCII Value of Character i = 105

The ASCII Value of Character a = 97

The ASCII Value of Character l = 108

The ASCII Value of Character s = 115

The ASCII Value of Character r = 114

The ASCII Value of Character a = 97

The ASCII Value of Character c = 99

The ASCII Value of Character k = 107


Related Posts



Comments

Recent Posts
Tags