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
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)
Comments
Leave a comment