Answer to Question #186788 in Python for desmond

Question #186788

a. Write a for loop that prints the ASCII code of each character in a string named S. Use the built-in function ord(character) to convert each character to an ASCII integer.

b. Next, change your loop to compute the sum of the ASCII codes of all characters in a string


1
Expert's answer
2021-04-29T13:58:01-0400

a.

s = input('Please input string S: ')
for x in s:
    print('symbol: ' + x + ', ASCII code: ' + str(ord(x)))

b.

s = input('Please input string S: ')
sum = 0
for x in s:
    sum += ord(x)
print(sum)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS