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