Answer to Question #261469 in Python for anji

Question #261469

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


1
Expert's answer
2021-11-05T03:18:50-0400
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)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS