print new string first character is the middle character of original string

#For a string (three characters and more) that you have created please create a new string that follows the next rules:
The first character of the new string is the middle character of the original string.
The middle character of the new string is the last character of the original string.
The last character of the new string is the first character of the original string.
Example:
For odd length case, length of 9 characters:
Let’s assume that the middle character is 9/2 rounded down that’s means that it is 4.
“afffbeeec” –> “bfffceeea”
For even length case, length of 8 characters:
The middle character is also 4 because 8/2 equals 4.
“axxxbyyc” -> “bxxxcyya”
Print your new string in the following way, for even length example:
The rotated string is bxxxcyya

this question was made me mad man i cannot planing the solve solution of that
need help

>Solution :

cast your string into a list, then it’s easy

a="afffbeeec"
b=list(a)
mid=len(b)//2
b[0], b[mid]=b[mid], b[0]
b[-1], b[mid]=b[mid], b[-1]
print(''.join(b))
>>> bfffceeea

Leave a Reply