×
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
1313    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
You cannot believe in God until you believe in yourself.
Swami Vivekananda
1719
57.18
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     43517
01/01/2018     36472
25/06/2018     35466
28/06/2017     34546
02/08/2017     32968
01/08/2017     27455
06/07/2017     27200
15/05/2017     26835
14/07/2017     22453
21/04/2018     21105
softetechnologies