Home / Expert Answers / Computer Science / python-write-a-function-printstr-that-takes-a-list-of-integers-as-a-parameter-the-numbers-in-the-pa555

(Solved): Python Write a function printStr() that takes a list of integers as a parameter. The numbers in the ...



Python

Write a function printStr() that takes a list of integers as a parameter. The numbers in the list represent Unicode encodings, and the function prints the characters associated with the codes all on one line with no spaces between them. For example, if the function were called on the list [109, 111, 109], it would print mom to the screen since 'm' is encoded by 109 and 'o' is encoded by 111. If there are any non-numeric values, floating point numbers, or negative integers in the list, those values are skipped by the function since those do not correspond to valid encodings. For example, if the function were called on the list [109, -1, 111, 0.5, 109, '1'], it would print mom to the screen since the only valid values in the list are the ones from the previous example. Hint: Use exception handling to deal with invalid values. The function should not modify the list passed as a parameter in any way. The following shows several sample executions of the function. When testing, please cut and paste the lists below into IDLE. Your function must work correctly on all possible lists provided as parameters:

>>> lst1 = [84, 111, 100, 97, 121, 32, 105, 115, 32, 87, 101, 100, 110, 101, 115, 100, 97, 121, 46]
>>> lst2 = [37, 33, 35, 36, 33, 64, 35, 42, 36, 38, 35, 32, 73, 32, 119, 105, 115, 104, 32, 73, 32, 99, 111, 117, 108, 100, 32, 117, 110, 100, 101, 114, 115, 116, 97, 110, 100, 32, 116, 104, 105, 115, 32, 98, 101, 116, 116, 101, 114, 46]
>>> lst3 = [65, 110, 110, 105, 107, 97]
>>> lst4 = [65, 110, -3, 110, 105, -8.5, 11.1, 107, 'ten', 97]
>>> lst5 = []
>>> printStr(lst1)
Today is Wednesday.
>>> lst1
[84, 111, 100, 97, 121, 32, 105, 115, 32, 87, 101, 100, 110, 101, 115, 100, 97, 121, 46]
>>> printStr(lst2)
%!#$!@#*$&# I wish I could understand this better.
>>> lst2
[37, 33, 35, 36, 33, 64, 35, 42, 36, 38, 35, 32, 73, 32, 119, 105, 115, 104, 32, 73, 32, 99, 111, 117, 108, 100, 32, 117, 110, 100, 101, 114, 115, 116, 97, 110, 100, 32, 116, 104, 105, 115, 32, 98, 101, 116, 116, 101, 114, 46]
>>> printStr(lst3)
Annika
>>> lst3
[65, 110, 110, 105, 107, 97]
>>> printStr(lst4)
Annika
>>> lst4
[65, 110, -3, 110, 105, -8.5, 11.1, 107, 'ten', 97]
>>> printStr(lst5)
>>> lst5
[]



We have an Answer from Expert

View Expert Answer

Expert Answer



Question :-

Write a function printStr() that takes a list of integers as a parameter. The numbers in the list represent Unicode encodings, and the function prints the characters associated with the codes all on one line with no spaces between them. For example, if the function were called on the list [109, 111, 109], it would print mom to the screen since 'm' is encoded by 109 and 'o' is encoded by 111. If there are any non-numeric values, floating point numbers, or negative integers in the list, those values are skipped by the function since those do not correspond to valid encodings. For example, if the function were called on the list [109, -1, 111, 0.5, 109, '1'], it would print mom to the screen since the only valid values in the list are the ones from the previous example. Hint: Use exception handling to deal with invalid values. The function should not modify the list passed as a parameter in any way. The following shows several sample executions of the function. When testing, please cut and paste the lists below into IDLE. Your function must work correctly on all possible lists provided as parameters:
>>> lst1 = [84, 111, 100, 97, 121, 32, 105, 115, 32, 87, 101, 100, 110, 101, 115, 100, 97, 121, 46] >>> lst2 = [37, 33, 35, 36, 33, 64, 35, 42, 36, 38, 35, 32, 73, 32, 119, 105, 115, 104, 32, 73, 32, 99, 111, 117, 108, 100, 32, 117, 110, 100, 101, 114, 115, 116, 97, 110, 100, 32, 116, 104, 105, 115, 32, 98, 101, 116, 116, 101, 114, 46] >>> lst3 = [65, 110, 110, 105, 107, 97] >>> lst4 = [65, 110, -3, 110, 105, -8.5, 11.1, 107, 'ten', 97] >>> lst5 = [] >>> printStr(lst1) Today is Wednesday. >>> lst1 [84, 111, 100, 97, 121, 32, 105, 115, 32, 87, 101, 100, 110, 101, 115, 100, 97, 121, 46] >>> printStr(lst2) %!#$!@#*$&# I wish I could understand this better. >>> lst2 [37, 33, 35, 36, 33, 64, 35, 42, 36, 38, 35, 32, 73, 32, 119, 105, 115, 104, 32, 73, 32, 99, 111, 117, 108, 100, 32, 117, 110, 100, 101, 114, 115, 116, 97, 110, 100, 32, 116, 104, 105, 115, 32, 98, 101, 116, 116, 101, 114, 46] >>> printStr(lst3) Annika >>> lst3 [65, 110, 110, 105, 107, 97] >>> printStr(lst4) Annika >>> lst4 [65, 110, -3, 110, 105, -8.5, 11.1, 107, 'ten', 97] >>> printStr(lst5) >>> lst5 []


We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe