Answer to Question #225613 in Python for kaavya

Question #225613

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-08-16T14:52:28-0400
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")

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
APPROVED BY CLIENTS