Given the strings s1 and s2, not necessarily of the same length, create a new st
ID: 3764394 • Letter: G
Question
Given the strings s1 and s2, not necessarily of the same length, create a new string consisting of alternating characters of s1 and s2 (that is, the first character of s1 followed by the first character of s2, followed by the second character of s1, followed by the second character of s2, and so on. Once the end of either string is reached, no additional characters are added. For example, if s1 contained "abc" and s2 contained "uvwxyz", then the new string should contain "aubvcw". Assign the new string to the variable s3. Write in Python
Explanation / Answer
s1 = "abcdefg"
s2 = "hijk"
s3 = ""
minLen = min(len(s1), len(s2))
for x in range(minLen):
out += s1[x]
out += s2[x]
out += s1[minLen:]
print out
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.