Question: Need Python code for this! Thanks! 4.30 LAB: Magic String The code template below takes as input two strings: the first, my_string, is a string

Need Python code for this! Thanks!

Need Python code for this! Thanks! 4.30 LAB: Magic String The code

4.30 LAB: Magic String The code template below takes as input two strings: the first, my_string, is a string literal of unknown length, and the second, magic, is a three-character string. Complete the program to assign the variable my_result with one of four possible values: 3, if magic is a substring of my_string; 2, if any two-character substring of magic is also a substring of my_string but magic itself is not. 1, if any of the characters in magic appears in my_string, but no two-character substrings nor magic are substrings of my_string: O, if no characters in magic appear at all in my_string. For example, suppose my_string is 'The main architect was Slartibartfast.'. Then if magic is 'art', my_result is 3 since art is a substring of my_string. If magic is 'arx', my_result is 2 because 'ar' is a two character substring of my_string. If magic is jxm, my_result is 1, because 'm is a one character substring of my_string. If magic is xjz, my_result is 0, of course. You may assume magic always has only three unique characters that need not be letters). You should assume case sensitivity; that is, for example, a and A are not the same letter Some hints: 1. The expression magic in my_string returns True if the string literal labeled with the name magic is a substring of the string literal labeled with the name my_string. 2. magic[0] returns the oth (that is, the first) character in magic magic[1] returns the 1st that is, the second) character in magic, and so on 3. magic[0:2] returns a string built from the oth and 1st characters of magic magic[1:3] contains the 1st and 2nd only

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!