Select Page

def loopy_madness(string1, string2): # finding length of both… def loopy_madness(string1, string2): # finding length of both strings len1 = len(string1) len2 = len(string2) # finding maximum length between two strings # now the target will be to match the size of smaller string # with the size of larger string max_length = max(len1, len2) # empty string to store the result string = “” # if size of string1 is 1 then # generating string1 times max_length if len1 == 1: string1 = string1 * max_length # if size of string2 is 1 then # generating string2 times max_length elif len2 == 1: string2 = string2 * max_length # if string1 is bigger elif len1 > len2: # assigning string2 to temp variable temp = string2 # loop will run max_length time for i in range(max_length):# string2[:-1] will geive a string excluding last character# string2[:-1][::-1] will reverse the string # string2[1:] will give the string excluding first character# concatenating these two and storing in temptemp += string2[:-1][::-1] + string2[1:] # now picking only max_length size string from temp and storing to string2 string2 = temp[:max_length] elif len2 > len1: # assigning string1 to temp variable temp = string1 # loop will run max_length times for i in range(max_length):# string1[:-1] will geive a string excluding last character# string1[:-1][::-1] will reverse the string # string1[1:] will give the string excluding first character# concatenating these two and storing in temptemp += string1[:-1][::-1] + string1[1:] # now picking only max_length size string from temp and storing to string1 string1 = temp[:max_length] for i in range(max_length):# adding one character from string1 and one from string2# and accumulating to string variablestring += string1[i] + string2[i] # returning string return stringprint(loopy_madness(“abc”, “123”))print(loopy_madness(“abcde”, “12”))print(loopy_madness(“abcdfe”, “123”))print(loopy_madness(“ab”, “123”))Now what U need to do is…The exact same function as loopy_madness….ut we ask that youchange any for loops that you used to while loops.Computer ScienceEngineering & TechnologyPython Programming PROG 70030

Order your essay today and save 20% with the discount code ESSAYHELP