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 change_letter(sentence:str):
alpha_s = 'abcdefghijklmnopqrstuvwxyz'
alpha_c = alpha_s.upper()
dict1 = dict(zip(alpha_s, alpha_s[1:] + alpha_s[:1]))
dict2 = dict(zip(alpha_c, alpha_c[1:] + alpha_c[:1]))
dict1.update(dict2)
input_text2 = sentence
output_text2 = ''
for c in input_text2 :
output_text2 += dict1.get(c, c)
print(output_text2)
Comments
Leave a comment