Replacing Characters of Sentence
You are given a string
S. Write a program to replace each letter of the string with the next letter that comes in the English alphabet.
Note: Ensure that while replacing the letters, uppercase should be replaced with uppercase letters, and lowercase should be replaced with lowercase letters.
The first line of input is a string.
In the given example, Hello World.
If we replace each letter with the letter that comes next in the English alphabet,
H becomes I, e becomes f and so on ... So, the output should be Ifmmp Xpsme.
Sample Input 1
Hello World
Sample Output 1
Ifmmp Xpsme
Sample Input 2
Something is better than Nothing
Sample Output 2
Tpnfuijoh jt cfuufs uibo Opuijoh
def ChangeLetters(str1):
list1 = list(str1.split(" "))
res = ""
for idx in range(97, 97 + 26):
res = res + chr(idx) + " "
list2 = list(res.split(" "))
l = len(list1)
for i in list1:
i =i.lower()
i = list(i)
l1 = len(i)
str2 = " "
for r in i:
ind = list2.index(r)
str2 += list2[ind + 1]
print(str2.title(), end='')
print("Sample Input 1")
print("Hello World")
print("Sample output 1")
ChangeLetters("Hello World")
Comments
Leave a comment