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.
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))
Comments
Leave a comment