Question: Write a python function decode(message, key, output) that reads in two input files, 1) the first file (called message) contains a string of space-separated integers

Write a python function decode(message, key, output) that reads in two input files, 1) the first file (called message) contains a string of space-separated integers 2) the second file (called key) contains a multi-line string, where each line is of the form "integer: word" that reads both of these files and replaces each integer in the message with the corresponding word found in key. The function should then write this decoded message into the specified output file.

def test_decode(): # test 1 decode("message.txt", "key.txt", "decoded.txt") f = open("decoded.txt", "r") result = f.readlines() assert(result == ["hope everyone is having lots and lots of fun"]) f.close() # test 2 decode("message1.txt", "key1.txt", "decoded1.txt") f = open("decoded1.txt", "r") result = f.readlines() assert(result == ["i love my cat and my cat loves me"]) f.close() print("done!")

"""message 4 1 6 3 2 7 2 9 5 """ """message1 3 7 5 1 10 5 1 11 6 """ """key 1: everyone 2: lots 3: having 4: hope 5: fun 6: is 7: and 9: of """ """key1 1: cat 2: tree 3: i 4: no 5: my 6: me 7: love 8: but 9: the 10: and 11: loves """

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!