question archive In: Exercise 6 - Loudmouth, Senior ii Remember when you did the homework exercises on Lord and Lady Loudmouth, reformatting their text to reflect specific typing quirks using regular expressions? Let's add one more member of the Loudmouth family

In: Exercise 6 - Loudmouth, Senior ii Remember when you did the homework exercises on Lord and Lady Loudmouth, reformatting their text to reflect specific typing quirks using regular expressions? Let's add one more member of the Loudmouth family

Subject:Computer SciencePrice:3.87 Bought7

In: Exercise 6 - Loudmouth, Senior ii Remember when you did the homework exercises on Lord and Lady Loudmouth, reformatting their text to reflect specific typing quirks using regular expressions?

Let's add one more member of the Loudmouth family. Loudmouth Senior is an old man who has to take a break after every two words, so a sentence like 'My name is Kalina' would become 'My name... is Kalina.,..', and 'I teach LlN120' would become 'I teach... LlN120.I Write code that takes an input from the user, and reformats the text to fit this pattern. Hint: this isn't as simple as writing a regular expression. Remember that, to insert text, you have to replace a sequence with itself plus the new item. Instead, you must tokenize the sentence first, then manually mark the boundaries. When rebuilding your final string, remember that you can use 'for' to go item-by—item through a list!

pur-new-sol

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE

Answer Preview

Answer:

 

def processString(inputString):
    # first spit the string into individual tokens/words
    words = inputString.split(" ")
    answer = ""

    # now iterate on indexes of words list
    # and then at every alternate index we add "..." to the answer string
    for i in range(len(words)):
        answer = answer +  " " + words[i]
        if i % 2 == 1:
            answer = answer + "..."

    # finally return the answer string
    return answer

if __name__ == "__main__":
    # take input from the user
    inputString = input("Enter a string: ")

    # precess the string into a format 
    formattedString = processString(inputString)

    # display the formatted string
    print("Formatted string: ", formattedString)