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
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)
Comments
Leave a comment