r/pythonhelp • u/[deleted] • Apr 29 '22
How do I remove/add certain characters to a sentence?
Hi there, I’m new to python and I have to make a simple translator app that requires changing/removing words with certain criteria from an inputted sentence. Can anyone tell me how I’d do that? Below is the question for reference:
During a camping trip, your family came up with a secret language. Since you are doing an Information Systems course, your family asked you to make a program to help translate English to your secret language. The secret language works this way: If a word begins with a vowel (a, e, i, o, u) - you add "py" to the end of the word. If a word begins with a consonant - you remove that first consonant. Write a program that uses a function to translate a given English sentence to the secret language. Test your function by printing the sentence: "An espresso a day keeps the doctor away". It should print the following “Anpy espressopy apy ay eeps he octor awaypy”.
1
u/MrHyderion Apr 30 '22
Here's a basic structure of how I would do it:
Get the sentence as input.
Split the sentence into a list of words
Iterate through the list, each time checking the respective word's first letter and changing it accordingly.
Join and print the sentence.
Profit!