×
FREE ASSISTANCE FOR THE INQUISITIVE PEOPLE
Tutorial Topics
X
softetechnologies
use of replace() function String Examples
String Example South point school assignment 16 - Python Language
244    Arnab De    29/01/2021   

Write a Python program to input a sentence from the user and then create an encoded version of the sentence by using the following rules. Finally print the original and the encoded sentences. The rules to be followed are

  1. A to W will get converted to D to Z respectively.
  2. X to Z will get converted to A to C respectively.
  3. a to v will get converted to e to z respectively.
  4. w to z will get converted to a to d respectively.
  5. A blank space will get converted to !
  6. All other characters will get copied as it is

Enter Sentence: 2nd October
Original Sentence = 2nd October
Coded sentence = 2rh!Rgxsfiv

Enter Sentence: The 36th Chamber of Shaolin
Original Sentence = The 36th Chamber of Shaolin
Coded sentence = Wli!36xl!Fleqfiv!sj!Vlepmr

strin=input("Enter A String : ")
strout=""
for x in strin:
    k=ord(x)
    if (k==32):
        strout +="!"
    elif(k>=65 and k<90):
        k=k+3
        if(k>90):
            k=k-26
        strout += chr(k)
    elif(k>=97 and k<=122):
        k=k+4
        if(k>122):
            k=k-26
        strout += chr(k)
    else:
        strout +=chr(k)
print("Original Sentence = ",strin)
print("Coded Sentence = ",strout)
use of replace() function String Examples
softetechnologies
Author Details
Arnab De
I have over 16 years of experience working as an IT professional, ranging from teaching at my own institute to being a computer faculty at different leading institute across Kolkata. I also work as a web developer and designer, having worked for renowned companies and brand. Through tutorialathome, I wish to share my years of knowledge with the readers.
Enter New Comment
Comment History
No Comment Found Yet.
Swami Vivekananda
Education is the manifestationof the perfection already in man.
Swami Vivekananda
337
23.83
Today So Far
Total View (Lakh)
softetechnologies
01/01/2018     30778
28/06/2017     25550
02/08/2017     22003
26/05/2018     19716
15/05/2017     19354
06/07/2017     17901
21/04/2018     16863
01/08/2017     16539
01/07/2017     14551
25/04/2018     13616
softetechnologies