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:
Answer rating: 100% (QA)
Certainly Heres an implementation of the decodestring function based on the requirements python def ... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
A wing has a planform area S of 200 ft and a total span b of 40 feet. The airfoils are symmetric all along the span. The airfoil has a 2-D lift curve slope of 2 per radian. The wing has a rectangular...
-
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?
-
Refer to the Thorson Tackle Shop data in Exercise 6-6. Assume that Thorson is using a periodic inventory system. Inventory on hand at December 31, 2014, was $38,000, based on the physical count. In...
-
The Coca-Cola Company is a global soft drink beverage company (ticker: KO) that is a primary and direct competitor with Starbucks. The following data for Coca-Cola include the actual amounts for 2015...
-
What problems arise when transfer pricing is used?
-
Assume Baja Company has the following reported amounts: Sales $510,000, Sales returns and allowances $15,000, Cost of goods sold $350,000, Operating expenses $110,000. Compute the following: (a) Net...
-
point(s) possible Submit test Identify a pattern in the list of numbers. Then use this pattern to find the next number. 26, 22, 18, 14, 10, OA. 4 B. 0 OC. 2 OD. 6
-
Moogle, Inc. Profit and Loss August 2017 - January 2018 Aug 2017 Sep 2017 Oct 2017 Nov 2047 Dec 2017 Jan 2018 Income 4020 Baronun 4010 Rovenun - FPL 2,304 4819 101,884 280.37 4020 Disputed Loon...
-
Mr. H turns on his fan and the three blades (25 cm each) experience a ccw angular acceleration of 3 rad/s/s. What is the angular displacement after the first 20 seconds. ? At the end of the day when...
-
i) Express tan-1 cosx 1-sinx 2 -
-
A baseball sits on a tee-ball stand. A child hits it with a bat moving east at 6.0 m/s and the ball flies off at 15 m/s. Determine the speed and direction of the bat immediately after impact....
-
You run an outside sales and marketing company and are an expert in the field. You have been tasked to help your client, the Charlotte Hornets, on incorporating the metaverse with the goal of...
-
1. The fastest-recorded baseball pitch was delivered by Nolan Ryan in 1974. The pitch was clocked at 100.9 mi/h (45.0 m/s). What is the impulse required to give a 0.145-kg baseball such a momentum?...
-
Use this research article: Wei, M., Su, J. C., Carrera, S., Lin, S. P., & Yi, F. (2018) The roles of childhood maltreatment and adult attachment in the development of depressive and anxiety symptoms...
-
Use translations to graph f. f(x) = x-/2 +1
-
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...
-
A retailer purchases a can of soup for 24 cents and sells it for 36 cents. Calculate the markup as a percentage of cost and as a percentage of selling price.
-
The characteristics of services affect the development of marketing mixes for services. Choose a specific service and explain how each marketing mix element could be affected by these service...
-
Identify a familiar product that recently was modified, categorize the modification (quality, functional, or aesthetic), and describe how you would have modified it differently.
Study smarter with the SolutionInn App