Answer to Question #242648 in Python for Rishi

Question #242648
Give a string writen a program to mirror the characters of the string in alphabetical order to create a secret message
1
Expert's answer
2021-09-27T18:12:17-0400
def cipher(s):
    res = ''
    ia = ord('a')
    iz = ord('z')
    iA = ord('A')
    iZ = ord('Z')
    for ch in s:
        i = ord(ch)
        if ia <= i <= iz:
            res += chr(iz -(i-ia))
        elif iA <= i <= iZ:
            res += chr(iZ -(i-iA))
        else:
            res += ch
    return res

def main():
    line = input('Enter a string - ')
    secret = cipher(line)
    print('Secret message is', secret)

if __name__== '__main__':
    main()

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