-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMerge_two_string.py
More file actions
62 lines (51 loc) · 925 Bytes
/
Merge_two_string.py
File metadata and controls
62 lines (51 loc) · 925 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
'''
a = input("Your first string.")
b = input("Your second string.")
print (a+b)
'''
#s1='ram'
#s2='sin'
#output= rsaimn
#merge 2 string alternatively letters.
a = input("Your first string.")
b = input("Your second string.")
i=0
j=0
newstring="" # take a empty string
while i< len(a) and j<len(b):
newstring += a[i]
newstring += b[j]
i+=1
j+=1
while i<len(a):
newstring += a[i]
i+=1
while j<len(b):
newstring += b[j]
j+=1
print(newstring)
"""
# if a and b length are same.
a = input("Your first string.")
b = input("Your second string.")
i,j=0,0
op=''
while i< len(a) or j<len(b):
op=op+a[i]+b[j]
i+=1
j+=1
print(op)
# if a and b length are diff.
a = input("Your first string.")
b = input("Your second string.")
i,j=0,0
op=''
while i< len(a) or j<len(b):
if i<len(a):
op=op+a[i]
i+=1
if i<len(b):
op=op+b[j]
j+=1
print(op)
"""