Question: Create a function called encoder which expects two arguments. The first argument is a string representing a message to be translated into a coded
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
Step by Step Solution
3.48 Rating (161 Votes )
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
