1. Given a string and a number N, develop a python code to mirror the characters from N-th position up to the length of the string in the alphabetical order. In mirror operation, we change ‘a’ to ‘z’, ‘b’ to ‘y’, and so on.
Input : N = 3
paradox
Output : paizwlc
Here , mirror characters from position 3 to end.
Input : N = 3
pneumonia
Output : pnefnlmrz 2 L6 CO3
Answers
Answer:
Given a user input string and the position from that position we need to mirror the characters up to the length of the string in the alphabetical order. In this operation, we change ‘a’ to ‘z’, ‘b’ to ‘y’, 'c' to 'x', 'd' to 'w' and so on means that the first character becomes the last and so on.
Inpu t: p = 3
Input string = python
Output : pygslm
Algorithm
Step 1: Input the string and position from we need to mirror the characters.
Step 2: Creating a string which is stored in alphabetical order.
Step 3: Create an empty string.
Step 4: Then traverse each character up to the position from where we need a mirror and up to this sting is unchanged.
Step 5: From that position up to the length of the string, we reverse the alphabetical order.
Step 6: Return the string.
Example Code
# Python program to find mirror characters in string
def mirror(str1, n):
# Creating a string having reversed
# alphabetical order
alphaset = "zyxwvutsrqponmlkjihgfedcba"
l = len(str1)
# The string up to the point specified in the
# question, the string remains unchanged and
# from the point up to the length of the
# string, we reverse the alphabetical order
result = ""
for i in range(0, n):
result = result + str1[i];
for i in range(n, l):
result = (result +
alphaset[ord(str1[i]) - ord('a')]);
return result;
# Driver function
str1 = input("Enter the string ::>")
n = int(input("Enter the position ::>"))
result = mirror(str1, n - 1)
print("The Result ::>",result)