Create a function called encoder which expects two arguments. The first argument is a string representing...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Create a function called encoder which expects two arguments. The first argument is a string representing a message to be translated into a coded message. The second argument is a list of lists serving as the key to be used to convert the original string to its coded equivalent. Each two-element list in the key represents a character that might be found in the original message paired with the character that will be substituted for the original character while building the coded message. The function returns a new string created by replacing every character in the message with its counterpart. This function does not print anything. (Hint: you could simplify things by decomposing the encoder function into smaller functions. Writing encoder as one big function could get complicated.) Usually the string passed as the first argument (the message) will include only the characters found as the first elements of the lists within the list that is passed as the second argument (the key). But if something other than one of those characters is found in the message, your function should translate the unexpected character into "?" as shown in the example using test3 below. >>>codel = [['a', 'n'],['b', 'o'l,['c', 'p'],['d', 'q'], ['e', 'r','f', 's'],['g', 't','h', 'u ['1', 'v'],['j', 'w'],['k', 'x'],['1', 'y'l, ['m', 'z'], ['n', 'a'l.l'o', 'b'l,['p', 'c'), 'f'],['t', 'g'l, '', ['x', 'k'], ['q'. 'd'],I'r', 'e'],['s', ['u', 'h'],['v', 'i'],[' ['y', '1'],['z', 'm'],[' 11. >>>code2= [[1,11, 12', 'e'1,['3'. #1.1'4', '$'],['5', '8'], ['6','], ['7','&'],['8', 1.1'9', '(1,['0',') ']] >>> testl="the quick brown fox jumped over the lazy dog" >>> test2 = "i do not like green eggs and ham" >>> test3 = "we can't stop!" >>> test4 - ** >>> test5 = "9876543210" >>> encoder (testi, codel) qur dhvpx oebja sbk whzerq bire gur yaml qbt' >>> x = encoder (test2, codel) >>> print (x) v qb abg yvxr terra rttf naq unz Create a function called encoder which expects two arguments. The first argument is a string representing a message to be translated into a coded message. The second argument is a list of lists serving as the key to be used to convert the original string to its coded equivalent. Each two-element list in the key represents a character that might be found in the original message paired with the character that will be substituted for the original character while building the coded message. The function returns a new string created by replacing every character in the message with its counterpart. This function does not print anything. (Hint: you could simplify things by decomposing the encoder function into smaller functions. Writing encoder as one big function could get complicated.) Usually the string passed as the first argument (the message) will include only the characters found as the first elements of the lists within the list that is passed as the second argument (the key). But if something other than one of those characters is found in the message, your function should translate the unexpected character into "?" as shown in the example using test3 below. >>>codel = [['a', 'n'],['b', 'o'l,['c', 'p'],['d', 'q'], ['e', 'r','f', 's'],['g', 't','h', 'u ['1', 'v'],['j', 'w'],['k', 'x'],['1', 'y'l, ['m', 'z'], ['n', 'a'l.l'o', 'b'l,['p', 'c'), 'f'],['t', 'g'l, '', ['x', 'k'], ['q'. 'd'],I'r', 'e'],['s', ['u', 'h'],['v', 'i'],[' ['y', '1'],['z', 'm'],[' 11. >>>code2= [[1,11, 12', 'e'1,['3'. #1.1'4', '$'],['5', '8'], ['6','], ['7','&'],['8', 1.1'9', '(1,['0',') ']] >>> testl="the quick brown fox jumped over the lazy dog" >>> test2 = "i do not like green eggs and ham" >>> test3 = "we can't stop!" >>> test4 - ** >>> test5 = "9876543210" >>> encoder (testi, codel) qur dhvpx oebja sbk whzerq bire gur yaml qbt' >>> x = encoder (test2, codel) >>> print (x) v qb abg yvxr terra rttf naq unz
Expert Answer:
Related Book For
Building Java Programs A Back To Basics Approach
ISBN: 9780135471944
5th Edition
Authors: Stuart Reges, Marty Stepp
Posted Date:
Students also viewed these programming questions
-
A firm plans to issue new shares of preferred stock to fund a new project. The new preferred stock shares will offer an annual dividend of $6 and will be sold to investors at a price of $100. The...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Read the case study "Southwest Airlines," found in Part 2 of your textbook. Review the "Guide to Case Analysis" found on pp. CA1 - CA11 of your textbook. (This guide follows the last case in the...
-
Roasters Limited is a coffee-blending firm. It produces a special blend of coffee known as "Utopia Blend" by mixing two grades of coffee "AB" and "QP" as follows: Material AB QP Standard mix ratio AB...
-
Develop a brief answer to each of the following questions: 1. Nimish Banks, a star college basketball player, received a contract from the Midwest Blazers to play professional basketball. The...
-
Rental equipment is for sale for $110,000. A prospective buyer estimates he would keep the equipment for 12 years and spend $6000 a year on maintaining the equipment. Estimated annual net receipts...
-
Spice Inc. issued bonds payable on December 31. Spice's bonds were dated July 31. Which statement is true of Spice's journal entry to record issuance of the bonds payable? a. Spice must pay one...
-
Aurora, Inc. estimates manufacturing overhead costs for the 2019 accounting period as follows: Equipment depreciation............................................ $344,000...
-
Investigate and present the strategies organizations can adapt to manage diversity effectively in this contemporary work environment.
-
A headlight produced by Enterprise Lumiere was found to be defective. The company has three factories (labeled below as A. B, and C) where such headlights are manufactured. A Quality Control Manager...
-
With level strategy, how many workers would be needed during a planning horizon of four periods if the production requirements in periods 1, 2, 3, and 4 are 1,000, 800, 1,200 and 1,100 units,...
-
At which stage in a project should you inform your customer that you are not able to deliver on schedule?
-
The Rumpel Company purchased a felt press last year at a cost of $7,500. The machine is 5-year property with depreciation rates of 20%, 32%, and 19.2% in the first three years. The book value after...
-
What the work and effort to manage one's emotions to keep them under control is called? Explain.
-
10 U.S.C. 2466 states: A. The secretary at the fan show designate each depot, level activity or military arsenal facility as the center of industry and technical excellence in the recognition court...
-
6.Taussig Corp.'s bonds currently sell for $1,150. They have a 6.35% annual coupon rate and a 20-year maturity, but they can be called in 5 years at $1,067.50. Assume that no costs other than the...
-
(Signaling) There are three types of workers, type 1, 2, and 3, whose marginal prod- ucts are $40, $80, and $100 respectively. The fraction of each type is 1/3. Employers observe only the worker's...
-
Dan and Diana file a joint return. Dan earned $31,000 during the year before losing his job. Diana received Social Security benefits of $5,000. a. Determine the taxable portion of the Social Security...
-
Describe the overall preconditions placed on the list class in this section. What assumptions do we make about how clients will use the list?
-
The following code attempts to draw a black-filled outer rectangle with a white-filled inner circle inside it: DrawingPanel panel = new DrawingPanel(200, 100); Graphics g = panel.getGraphics();...
-
Figure 12.12 shows only part of the decision tree for the first two levels. How many entries are there at the second level of the full tree? How many are at level 3 of the full tree? empty col l row...
-
What is the average rate of return for the values that follow? 0.90, 1.1, 1.2
-
What is the average rate of return for the values that follow? 0.80, 2.0, 5.0
-
State whether the data are symmetrical, skewed to the left, or skewed to the right. 16; 17; 19; 22; 22; 22; 22; 22; 23
Study smarter with the SolutionInn App