Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function in python def encode(msg,secret_d): Consider a string msg and a

ID: 3684461 • Letter: W

Question

Write a function in python def encode(msg,secret_d): Consider a string msg and a dictionary, secret_d, where the keys are single-character strings and values are strings. For every character ch in msg, the function should search in the dictionary and replace it with the mapping string if ch is a key in secrect_d. If ch is not a key in secrect_d, it should be kept unchanged.

o msg: a string to be encoded
o secret_d: a dictionary that maps single characters to strings.

o Return value: an updated version of msg after replacement.

Examples:

encode("CAN YOU READ THIS",{'A':'4','E':'3','T':'7','I':'1','S':'5'}) 'C4N YOU R34D 7H15'

encode("S+EWWE1+++",{'+':'0','S':'7','E':'3','W':'9'}) '7039931000'

Explanation / Answer

Solution for Question :

This below python script will read the message and charcter will store in the dictionary
and will perform the encryption.

def endcode(msg,secret_d):
   newstr=""
   for ch in msg:
   for key,value in secret_d.iteritems():
   if ch == key:
   newstr=newstr+value
   if(ch not in secret_d):
   newstr=newstr+ch
   print(newstr)
  
endcode('CAN YOU READ THIS',{'A':'4','E':'3','T':'7','I':'1','S':'5'})

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote