Answer to Question #226581 in Python for kaavya

Question #226581

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-16T05:48:38-0400
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)

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