Answer to Question #265997 in Python for sai krishna

Question #265997

in the example the sentence is Nice Day.

the previous letter of N is M, similarly replace each letter with the previous letter

N i c e D a y

M h b d C z x

so the output should be Mhbd Czx

sample input 1

Nice Day

sample output 1

Mhbd Czx

sample input2

Be good and do good

sample output2

Ad fnnc zmc cn fnnc


1
Expert's answer
2021-11-15T17:30:15-0500


SOLUTION TO THE ABOVE QUESTION


SOLUTION CODE


#prompt the user to enter a sentence
print("\nINPUT:")
my_sentence = input("\nEnter a sentence: ")

sentence_length = len(my_sentence)

#Declare your new sentence
my_new_sentence = ""

for i in range(0,sentence_length):
    my_char = my_sentence[i]
    if(my_char==" "):
        my_new_sentence = my_new_sentence+my_char;
    elif(ord(my_char)==97):
        my_new_sentence = my_new_sentence + 'z'
    else:
        my_new_sentence=my_new_sentence+chr(ord(my_char)-1)
print("\nOUTPUT:")
print("\nMy original sentence is "+my_sentence)
print("\nMy new sentence is "+my_new_sentence)


SAMPLE OUTPUT PROGRAM






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