Answer to Question #265986 in Python for Pras

Question #265986

You are given a sentence Nice day Write a program to replace each letter with the previous letter in the english alphabet

1
Expert's answer
2021-11-15T00:22:43-0500

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) 

#This code considered by expert Umed


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