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


Expert's answer

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!

LATEST TUTORIALS
APPROVED BY CLIENTS