×
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
2105    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.
Albert Einstein
Few are those who see with their own eyes and feel with their own hearts.
Albert Einstein
3
80.82
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     54128
25/06/2018     45121
01/01/2018     43673
28/06/2017     41209
02/08/2017     40224
01/08/2017     34268
06/07/2017     34071
15/05/2017     33309
11/09/2018     30326
14/07/2017     29835
softetechnologies