Answer to Question #304540 in Python for reyad

Question #304540

Write a Python program that will take one input from the user made up of two strings separated by a comma and a space (see samples below). Then create a mixed string with alternative characters from each string. Any leftover chars will be appended at the end of the resulting string.



Hint: For adding the leftover characters you may use string slicing.



Note: Please do not use lists for this task.



=====================================================================



Sample Input 1:


ABCD, efgh



Sample Output 1:


AeBfCgDh

1
Expert's answer
2022-03-01T14:00:23-0500
line = input()
n1 = 0
i1 = 0
while line[n1] != ',':
    n1 += 1
i2 = n1 + 2
n2 = len(line)

res = ''
while i1 < n1 and i2 < n2:
    res += line[i1] + line[i2]
    i1 += 1
    i2 += 1

if i1 < n1:
    res += line[i1:n1]
else:
    res += line[i2:n2]

print(res)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS