Answer to Question #233979 in Python for Lovely

Question #233979

Not getting output please give a corrected code

Secret Message -1


Given a string, write a program to mirror the characters of the string in alphabetical order to create a secret message.


Note: Mirroring the characters in alphabetical order replacing the letters 'a' with 'z', 'b' with 'y', ..., 'z' with 'a'. You need to mirror both uppercase and lowercase characters. You can ignore mirroring for all characters that are not letters.


1
Expert's answer
2021-09-09T00:01:08-0400
def main():
    inputString = input("Your string: ")
    outputString=""
    for letter in inputString:
        reverseLetter=getReverseLetter(letter)
        if(reverseLetter!=-1):
            outputString+=str(reverseLetter)
        else:
            outputString+=letter


    print(outputString)

def getReverseLetter(letter):
    alphabet = "abcdefghijklmnopqrstuvwxyz"
    alphabetReverse = "zyxwvutsrqponmlkjihgfedcba"
    for i in range(0,len(alphabet)):
        if letter.islower() and letter==alphabet[i]:
            return alphabetReverse[i]
        if letter.isupper() and letter==alphabet[i].upper():
            return alphabetReverse[i].upper()
    return -1

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