## Saturday, October 17, 2020

Solution Exercise 48: python algorithm to concatenate two string in alternative way #### Exercise 48

Write a program as a function which takes as parameters a pair of strings (s1, s2) and which returns the string s obtained by concatenating in an alternative way the characters of s1 and s2. Example for (s1, s2) = ("Python" , "Java") the function returns the string s = 'PJyatvha'

#### Solution

``````# creating a function which test if given word contains at least one uppercase character
def concatenation(s1 , s2):
# initializing the concatenated string s
s = ""
n = len(s1)

m = len(s2)
if n < m :
for i in range(0 , n):
s = s + s1[i] + s2[i]
s = s + s2[n+1 : m]
else:
for i in range(0 , m):
s = s + s1[i] + s2[i]
s = s + s2[m+1 : n]

return s
print("The concatenated string is s = " ,concatenation("Python" , "Java"))

# The output is : The concatenated string is s =  PJyatvha``````

Younes Derfoufi
my-courses.net

## Python Exercises With Solutions

1. Python Arithmetic Exercises
2. Equations & System Of Equations
3. Polynomials and Functions
4. Python Arithmetic Exercises
5. Numpy, Matplolib, Sympy , Scipy - Exercises
6. Python Arithmetic Exercises

Younes Derfoufi

## Sample Text 