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.
Input
The first line of input is a string.
Explanation
In the given example,
Hello World.
If we replace each letter with the letter that comes next in the English alphabet,
H becomes I, e becomes f and so on ... So, the output should be Ifmmp Xpsme.
Sample Input 1
Hello World
Sample Output 1
Ifmmp Xpsme
Sample Input 2
Something is better than Nothing
Sample Output 2
Tpnfuijoh jt cfuufs uibo Opuijoh
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))
if __name__ == '__main__':
main()
Comments
Leave a comment