Q:

# Create a new string made of the first, middle, and last characters of each input string using python programming

### Create a new string made of the first, middle, and last characters of each input string

Given two strings, `s1` and `s2`, write a program to return a new string made of s1 and s2’s first, middle, and last characters.

Given:

``````s1 = "America"
s2 = "Japan"``````

Expected Output:

`AJrpan`

Hint:

• String index starts with index 0. The first character is present at index 0, and the last character is at the index string’s length -1
• Use built-in function `len(s1)` to get the string length.
• Next, get the middle index number by dividing string length by 2.

Solution:

• Get the first character from both strings, concatenate them, and store them in variable `x`
• Get the middle character from both strings, concatenate them, and store them in variable `y`
• Get the last character from both strings, concatenate them, and store them in variable x
• In the end, join `x``y`, and `z` and save it in the result `variable`
• print the `result`
``````def mix_string(s1, s2):
# get first character from both string
first_char = s1[0] + s2[0]

# get middle character from both string
middle_char = s1[int(len(s1) / 2):int(len(s1) / 2) + 1] + s2[int(len(s2) / 2):int(len(s2) / 2) + 1]

# get last character from both string
last_char = s1[len(s1) - 1] + s2[len(s2) - 1]

res = first_char + middle_char + last_char
print("Mix String is ", res)

s1 = "America"
s2 = "Japan"
mix_string(s1, s2)
``````