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
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
Comments
Leave a comment