Answer to Question #245120 in Python for Raju

Question #245120

Replacing Characters of Sentence

You are given a string S. Write a program to replace each letter of the string with the next letter that comes in the English alphabet.


Note: Ensure that while replacing the letters, uppercase should be replaced with uppercase letters, and lowercase should be replaced with lowercase letters.


1
Expert's answer
2021-10-04T04:57:36-0400
def enter_phrase():
    phrase = input('Enter phrase: ')
    return phrase

def capitalize_symbol(phrase):
    k = ""
    for i in phrase:
        if i != ' ':
            if i.istitle():
                next = chr(97 if i == 'z' else ord(i)+1)
                if next in ('a', 'e', 'i', 'o', 'u'):
                    next = next.capitalize()
                k += next.title()
            else:
                next = chr(97 if i == 'z' else ord(i) + 1)
                if next in ('a', 'e', 'i', 'o', 'u'):
                    next = next.capitalize()
                k += next.lower()
        else:
            k += ' '
    return k

def main():
    phrase = enter_phrase()
    print(capitalize_symbol(phrase))

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