Answered step by step
Verified Expert Solution
Question
1 Approved Answer
URGENT! THANK YOU! 2. Write a function weave(s1, s2) that takes as inputs two strings s1 and s2 and uses a loop to construct and
URGENT! THANK YOU!
2. Write a function weave(s1, s2) that takes as inputs two strings s1 and s2 and uses a loop to construct and return a new string that is formed by "weaving" together the characters in the strings s1 and s2 to create a single string. In other words, the new string should alternate characters from the two strings: the first character from s1, followed by the first character from s2, followed by the second character from s1, followed by the second character from s2, etc. If one of the strings is longer than the other, its "extra" characters - the ones with no counterparts in the shorter string - should appear immediately after the "woven" characters (if any) in the new string >>weaveC' aaaaaa', "bbbbbb'") abababababab >weave('abcde', 'VWXYZ aVbWcXdYeZ >>> weave(' aaaaaa', 'bb') # four extra 'a' characters at the end ababaaaa >>> weave(' aaaa', 'bbbbbb') # two extra 'b' characters at the end ababababbb >>>weave( aaaa', '") # all of the 'a' characters are extra! weave ', bbbb') # all of the 'b' characters are extra! weave(', '' You solved this problem using recursion in [Problem Set 2][ps2], but for this problem set you must use a loopStep 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