decode_string(encoded_string, You will now write a function encoder) that takes an encoded string (see definition in...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
decode_string(encoded_string, You will now write a function encoder) that takes an encoded string (see definition in question 6) and an encoder (of type dict, see question 5) as input, and returns a decoded string that was used to generate encoded_string. In other words, it must return a string such that calling encode_string(string, encoder) will return encoded_string. If there is more than one solution, it is OK to return one. You can view encoder as an output of a call to create_encoder (some_string) in question 5, and encoded_string as an output of a call to encode_string(some_string, encoder). But this question will be marked independently of questions 5 and 6, even if you did not solve question 5 or 6. For example, decode_string('02010201', {'a' : '01', 'b': '02', 'c': '03' }) should return 'baba'. decode_string('A 0201 0301t', {'a': '01', 'b': '02', 'c' : '03' }) should return 'A bad cat' decode_string('ABC 040506 ghijklmnopqrstuvwxyz', {'a': '01', 'b': '02', 'c': '03', 'd':'04', 'e': '05', 'f': '06'}) should return 'ABC def ghijklmnopqrstuvwxyz'. Requirements: The function that you write must be named decode_string and it must have two parameters. You can assume that the first argument is a string. You can assume that the second argument is a dictionary as defined in question 5. That means its keys are single non-numeric character and values are 2-digit number string. The function must return a string. A skeleton code file named decode_string.py is provided. You must write your solution into this file. Remember that: You must upload the python file with your solution using the right submission link for question 7 on wattle, before the end of the exam. You can re-upload it as many times as you wish during the exam, but we will mark this question based on the contents of the last uploaded file. The file must contain only syntactically correct python code (and comments). Do not import any module that you do not use. You must define a function named decode_string that has two parameters. You may also define additional functions if it helps you break down or solve the problem. def decode_string(encoded_string, encoder): def test_decode_string(): This function runs a number of tests of the decode_string function. If it works ok, you will just see the output ("all tests passed") at the end when you call this function; if some test fails, there will be an error message. assert decode_string('02010201 {'a : '01 'b' : '02 assert decode_string('A 0201d 0301t', {'a' : '01', 'b' : assert (decode_string('ABC 040506 ghijklmnopqrstuvwxyz', == { 'a':'01', 'b':'02','c':'03','d': '04' 'e': '05 'ABC def ghijklmnopqrstuvwxyz') 'abcd' assert decode_string('', {'a' : 01 'b' : '02', 'c': '03' }) assert decode_string('abcd', {}) assert decode_string('', {}) print("all tests passed") == : '03' }) '02' 'c' : '03' }) 3 ) 2 ) == 'baba' 'f': '06'}) == 'A bad cat' decode_string(encoded_string, You will now write a function encoder) that takes an encoded string (see definition in question 6) and an encoder (of type dict, see question 5) as input, and returns a decoded string that was used to generate encoded_string. In other words, it must return a string such that calling encode_string(string, encoder) will return encoded_string. If there is more than one solution, it is OK to return one. You can view encoder as an output of a call to create_encoder (some_string) in question 5, and encoded_string as an output of a call to encode_string(some_string, encoder). But this question will be marked independently of questions 5 and 6, even if you did not solve question 5 or 6. For example, decode_string('02010201', {'a' : '01', 'b': '02', 'c': '03' }) should return 'baba'. decode_string('A 0201 0301t', {'a': '01', 'b': '02', 'c' : '03' }) should return 'A bad cat' decode_string('ABC 040506 ghijklmnopqrstuvwxyz', {'a': '01', 'b': '02', 'c': '03', 'd':'04', 'e': '05', 'f': '06'}) should return 'ABC def ghijklmnopqrstuvwxyz'. Requirements: The function that you write must be named decode_string and it must have two parameters. You can assume that the first argument is a string. You can assume that the second argument is a dictionary as defined in question 5. That means its keys are single non-numeric character and values are 2-digit number string. The function must return a string. A skeleton code file named decode_string.py is provided. You must write your solution into this file. Remember that: You must upload the python file with your solution using the right submission link for question 7 on wattle, before the end of the exam. You can re-upload it as many times as you wish during the exam, but we will mark this question based on the contents of the last uploaded file. The file must contain only syntactically correct python code (and comments). Do not import any module that you do not use. You must define a function named decode_string that has two parameters. You may also define additional functions if it helps you break down or solve the problem. def decode_string(encoded_string, encoder): def test_decode_string(): This function runs a number of tests of the decode_string function. If it works ok, you will just see the output ("all tests passed") at the end when you call this function; if some test fails, there will be an error message. assert decode_string('02010201 {'a : '01 'b' : '02 assert decode_string('A 0201d 0301t', {'a' : '01', 'b' : assert (decode_string('ABC 040506 ghijklmnopqrstuvwxyz', == { 'a':'01', 'b':'02','c':'03','d': '04' 'e': '05 'ABC def ghijklmnopqrstuvwxyz') 'abcd' assert decode_string('', {'a' : 01 'b' : '02', 'c': '03' }) assert decode_string('abcd', {}) assert decode_string('', {}) print("all tests passed") == : '03' }) '02' 'c' : '03' }) 3 ) 2 ) == 'baba' 'f': '06'}) == 'A bad cat'
Expert Answer:
Related Book For
Posted Date:
Students also viewed these programming questions
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
You are a general contractor wishing to put up a modest-sized cement production plant on the outskirts of town. The plant would operate on only one 10-hour shift per day and would produce about 400...
-
How can adults continue to function relatively normally after surgery to remove the thymus, tonsils, spleen, or lymph nodes?
-
Jonesey Auto Supplies made the following purchases and sales of windshield wipers during March: Required 1. Assuming Jonesey Auto Supplies uses the perpetual inventory system, calculate the cost of...
-
R2. Using data described in Exercise 3, it is found that R2 = 0.68. Interpret that value. That is, what does that value tell us about the data?
-
What are some of symptoms of Functional Decompositions?
-
Milken Manufacturing has three product lines. The companys new accountant, Marvin LaSance, is responsible for allocating facility-level costs to these product lines. Mr. LaSance is finding the...
-
MBI LLC expects an EBIT of $2,300 every year forever. The company currently has no debt and is valued at $12,650. The tax rate is 23 percent. SHOW YOUR WORK 1) What will the value of the firm be if...
-
Journal entry to record the asset retirement obligation: (Drilling Platform is not correct for part a) c- Journal entry to record the asset retirement obligation along with asset (For better...
-
Which of the following best describes the approach that was used in the first gene therapy trial for treating SCID? a. The normal ADA gene was introduced by injecting liposomes directly into the...
-
Which of the following would not be consistent with the idea that a disorder has a genetic component? a. The disorder is more likely to occur among an affected persons relatives than in the general...
-
During the molecular process of homologous recombination between homologous chromosomes, a. a Holliday junction forms. b. branch migration occurs. c. a heteroduplex region forms. d. all of the above...
-
Which of the following mechanisms can result in gene conversion? a. DNA mismatch repair b. DNA gap repair c. Resolution of a Holliday junction d. Both a and b can result in gene conversion.
-
R esearchers can introduce loss-of-function mutations into genes using the CRISPR/Cas technology described in Chapter 20. If you used this technology to produce a homozygous loss-of-function mutation...
-
Petrodar oil company entered into a concessionary agreement with Namibia Government. Petrodar oil company agreed to pay the government 12% of gross production. The gross sales of Petrodar oil Company...
-
The Ferris wheel in the figure has a radius of 68 feet. The clearance between the wheel and the ground is 14 feet. The rectangular coordinate system shown has its origin on the ground directly below...
-
Use the RTD data in Examples 16-1 and 16-2 to predict X PFR , X CSTR , X LFR , X T-I-S , X seg and X mm for the following elementary gas-phase reactions a. A B k = 0.1 min 1 b. A 2B k = 0.1 min 1...
-
Hydrogen and O2 can be combined in fuel cells to generate electricity. Solar energy can be used to split water to generate the raw reactants H2 and O2 for fuel cells. One method of solar thermal...
-
The reactions described in Example 12-7 are to be carried out isothermally at 1000C in the reactor whose RTD is described in Example 17-4 with C A0 = C B0 = 0.05 mol/dm 3 . a. Determine the exit...
-
In the research on leader behaviors, which style of leadership describes the preferred high-high combination? (a) transformational (b) transactional (c) laissez-faire (d) democratic
-
When managers use offers of rewards and threats of punishments to try to get others to do what they want them to do, they are using which type of power? (a) formal authority (b) position (c) referent...
-
In terms of leadership behaviors, someone who focuses on doing a very good job of planning work tasks, setting performance standards, and monitoring results would be described as _________. (a) task...
Study smarter with the SolutionInn App