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.
Input
The first line of input is a string.
Explanation
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
sentence = input()
new_sentence = ""
for ch in sentence:
if ord(ch) == 122:
new_sentence += chr(97)
elif ord(ch) == 90:
new_sentence += chr(65)
elif (ord(ch) >= 97 and ord(ch) < 122) or (ord(ch) >= 65 and ord(ch) < 90):
new_sentence += chr(ord(ch)+1)
else:
new_sentence += ch
print(new_sentence)
Comments
Leave a comment