Question
5. Assume you decide to use more of your new Python skills, so you are going to write a function that looks for a string
5. Assume you decide to use more of your new Python skills, so you are going to write a function that looks for a string present in another string and enclosed in tags, extract it, and return the index position of the string. Also print out the resulting string. (Hint: Use either str.find( ) or str.index( ) method which accepts arguments and produces output as shown below. >>> xtrfrmtag("violet", "Wow a cake with a currant") Cake To encode a message, you look up letters in the original alphabet. Whatever index the letter is, you take the corresponding letter from the keyword cipher alphabetwhich you can easily generate if you know the keyword. Following there is the function encode. def encode(string,keyletters): alpha="abcdefghijklmnopqrstuvwxyz" secret = "" for letter in string: index = alpha.find(letter) secret = secret+keyletters[index] print secret _ >>> encode("this is a test","earthbcdfgijklmnopqsuvwxyz") sdfqzfqzezshqs
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started