Answer to Question #187263 in Python for kofi

Question #187263

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

4. Use a for loop and the list append method to generate the powers of 2 to produce the following result [1, 2, 4, 8, 16, 32, 64, 128]

5. Write a for loop that prints a dictionary's items in sorted (ascending) order


1
Expert's answer
2021-04-29T15:42:41-0400
S = 'example'
#a.prints the ASCII code of each character in a string named S.
print(*[ord(i) for i in s])
# b.the sum of the ASCII codes of all characters in a string
print(sum([ord(i) for i in s]))
# c.to generate the powers of 2 
print([2**i for i in range(8)])
# d.prints a dictionary's items in sorted
dict_example = {'first':'10','second':'2','three':'105','for':'72','five':'32'}
print(sorted([i for i in dict_example.items()]))

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