r/pythonhelp • • 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”.

0 Upvotes

3 comments sorted by

1

u/MrHyderion Apr 30 '22

Here's a basic structure of how I would do it:

  1. Get the sentence as input.

  2. Split the sentence into a list of words

  3. Iterate through the list, each time checking the respective word's first letter and changing it accordingly.

  4. Join and print the sentence.

  5. Profit!

1

u/[deleted] Apr 30 '22

Thanks so much for the help. Really appreciate it.

1

u/MrHyderion Apr 30 '22

You're welcome. Happy coding!