In: Computer Science
Creating a list/tuple
4. Write a program to accept a string from the user,
then replace the first letter with the last letter, the last letter
with the middle letter and the middle letter with the first letter.
E.g. “Billy” -> “yiBll”.
Code according to problem:
st = input('Enter String: ')
string = list(st)
string[0], string[len(string)-1] =
string[len(string)-1],string[0]
string[len(string)-1], string[int(len(string)/2)] =
string[int(len(string)/2)],string[len(string)-1]
string[0], string[int(len(string)/2)] =
string[int(len(string)/2)],string[0]
new=""
for x in string:
new += x
print(new)
Code according to example:
st = input('Enter String: ')
string = list(st)
string[0], string[len(string)-1] =
string[len(string)-1],string[0]
string[len(string)-1], string[int(len(string)/2)] =
string[int(len(string)/2)],string[len(string)-1]
new=""
for x in string:
new += x
print(new)
Actually the statement of code and the example does not match. But I gave you code for both according to the problem statement and the example.