Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading