The decoder dictionary consists of integer keys that represent codes. The value of each key is a single character string.
# variables for task 2
decoder = {80: 'P', 121: 'y', 116: 't', 104: 'h', 111: 'o', 110: 'n', 105: 'i', 115: 's', 99: 'c', 108: 'l', 46: '.', 32: ' ', 44: ',', 45: '-', 95: '_', 40: '(', 42: '*', 41: ')', 47: '/', 92: '\\', 61: '=', 39: "'", 124: '|', 96: '`', 58: ':', 59: ';'}
msg1 = [[80, 121, 116, 104, 111, 110], [105, 115], [99, 111, 111, 108, 46]]
msg2 = [[32, 32, 32, 44, 45, 46], [32, 95, 40, 42, 95, 42, 41, 95], [40, 95, 32, 32, 111, 32, 32, 95, 41], [32, 32, 47, 32, 111, 32, 92], [32, 40, 95, 47, 32, 92, 95, 41, 32]]
msg3 = [[32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 40], [32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 41], [32, 32, 32, 32, 32, 95, 95, 46, 46, 45, 45, 45, 46, 46, 95, 95], [32, 44, 45, 61, 39, 32, 32, 47, 32, 32, 124, 32, 32, 92, 32, 32, 96, 61, 45, 46], [58, 45, 45, 46, 46, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 46, 46, 45, 45, 59], [32, 92, 46, 44, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 44, 46, 47]]
![Message decodin
Iists, using dictionarles)
For task2, you'll use four variables in the starting code: decoder, msg1, msg2, msg3.
The decoder dictionary consists of integer keys that represent codes. The value of each key is a single character string.
The message strings (msg1, msg2, msg3) are lists of lists. Each inner list is a sequence of integers (code) that represents a
character in a string. Use the decoder dictionary to look up the correct character to convert the list to a string.
See diagram below:
The decoder variable is a dictionary where the key in an integer
|(code) and the associated value is a string with a single character.
decoder = { code: "Y', code:'z', code:"x' }
The msg1 variable(s) [there are three in your lab, msg1, msg2, msg3] are lists of lists.
Each inner list is a set of code numbers that represent a single
character in a string.
msgi - ( [code, code, code, .., code], .. ., [code, code, code .., code] 1
Convert the lists of codes to a string
(code, code, ., code)
decoder
Final string
Use the dictionary to
"String1"
"StringN"
(code, code, ., code]
decode the codes into
their associated characters.
Example
decoder - { 80: 'H", 14:'0', 1e1: 'e', 93:'1'}
decoded by dictionary
'H', 'e', '1', 'l', 'o'
final string
"Hello"
code list
[ве, 1е1, 93, 9з, 14]
->
Task 2 is to decode all three messages and print them out. In the following, I show the results of decoding messages: msg1, msg2.
I'm not showing msg3, so you can find out what it is on your own. Your output needs to have all three strings.
You have complete freedom to implement this task in anyway you want as long as the output is correct. You may introduce your
own functions. Before printing each message, print the message ID (i.e., 1, 2, or 3) above it as shown below:
----- Task 2
.-----
Message 1
Python
is
cool.
Example for msg1
msg1 = [[80, 121, 116, 104, 111, 110],
[105, 115], [99, 111, 111, 108, 46]]
---
----
msg1 variable is a list of 3 lists.
Each list is decoded with the help of the decoder
Message 2
---
----
dictionary to produce three strings as described
above.
(C o )
Print each string on its own line to get the final
decoded message.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F842ddfb5-3cba-4856-a7b3-78a95dca4dd5%2F64ba9a5f-7ed5-4052-b110-4142e9e4362c%2Fr9pu759_processed.png&w=3840&q=75)

Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images









