Question

In: Computer Science

Python Practice Sample:   Write code to replace every occurrence of THE or the with ### and...

Python Practice Sample:  

Write code to replace every occurrence of THE or the with ### and every word ending with the letter s to end with a $. Print the resulting text four words per line (and any remaining words from each paragraph on the last one of each paragraph)

"The modern business world goes way beyond the balance sheet. Whether your passion is finance or fashion, economics or the environment, you need an education built for business. At Bentley, we understand this. Sure, we started as an accounting school. But over the past 100 years, the business world has changed and we have too. Today, your classmates are dreaming of Silicon Valley or Washington D.C., just as often as Wall Street"

Solutions

Expert Solution

Python Program:

import re
para = "The modern business world goes way beyond the balance sheet. Whether your passion is finance or fashion, economics or the environment, you need an education built for business. At Bentley, we understand this. Sure, we started as an accounting school. But over the past 100 years, the business world has changed and we have too. Today, your classmates are dreaming of Silicon Valley or Washington D.C., just as often as Wall Street"

words = re.findall(r'[\w]+', para)
final_words = []
for i in words:
    if i.endswith("s"):
        j = i[:-1] + i[-1].replace("s", "$")  # replace ends with 's' by ends with '$'
        final_words.append(j)
    else:
        final_words.append(i)
        
for i in range(0, len(final_words), 4): # printing 4 words per line
    print(" ".join(final_words[i:i+4]).replace("The", "###").replace("the", "###")) # replace "The", "the" by "###"

Output:

Thumbs Up Please !!!


Related Solutions

Write the python code that generates a normal sample with given μ and σ, and the...
Write the python code that generates a normal sample with given μ and σ, and the code that calculates m (sample mean) and s (sample standard deviation) from the sample.
Write the python code that generates a normal sample with given μ and σ, and the...
Write the python code that generates a normal sample with given μ and σ, and the code that calculates m and s from the sample. Do the same using the Bayes’ estimator assuming a prior distribution for μ.
Please write in beginner level PYTHON code! Your job is to write a Python program that...
Please write in beginner level PYTHON code! Your job is to write a Python program that asks the user to make one of two choices: destruct or construct. - If the user chooses to destruct, prompt them for an alternade, and then output the 2 words from that alternade. - If the user chooses construct, prompt them for 2 words, and then output the alternade that would have produced those words. - You must enforce that the users enter real...
Python code Assignment Overview In this assignment you will practice with conditionals and loops (for). This...
Python code Assignment Overview In this assignment you will practice with conditionals and loops (for). This assignment will give you experience on the use of the while loop and the for loop. You will use both selection (if) and repetition (while, for) in this assignment. Write a program that calculates the balance of a savings account at the end of a period of time. It should ask the user for the annual interest rate, the starting balance, and the number...
code in python write a code where the initial value is compounded by a multiplier, rounded...
code in python write a code where the initial value is compounded by a multiplier, rounded to the nearest tenth Output: Initial Value: 10 Multiplier: 1.4 Number of compounds: 10 Your Values are: 10 , 14, 19.6 , 27.4, 38.4, 53.8, 75.3, 105.4, 147.6, 206.6
Every IRS agent's favorite code section... Practice Codebreaker 22 unread replies.22 replies. This is a practice...
Every IRS agent's favorite code section... Practice Codebreaker 22 unread replies.22 replies. This is a practice CodeBreaker -- it's worth just one point, so if you attempt to crack it, you get a point for trying. The better job you do, the better the feedback I can give you, but otherwise, it's just a free point. It's also a pretty easy section. 26 U.S. Code § 5203.Entry and examination of premises (b)Right of entry and examination It shall be lawful...
Please write in Python code Write a program that stores the following data in a tuple:...
Please write in Python code Write a program that stores the following data in a tuple: 54,76,32,14,29,12,64,97,50,86,43,12 The program needs to display a menu to the user, with the following 4 options: 1 – Display minimum 2 – Display maximum 3 – Display total 4 – Display average 5 – Quit Make your program loop back to this menu until the user chooses option 5. Write code for all 4 other menu choices
Using python as the coding language please write the code for the following problem. Write a...
Using python as the coding language please write the code for the following problem. Write a function called provenance that takes two string arguments and returns another string depending on the values of the arguments according to the table below. This function is based on the geologic practice of determining the distance of a sedimentary rock from the source of its component grains by grain size and smoothness. First Argument Value Second Argument Value Return Value "coarse" "rounded" "intermediate" "coarse"...
Code in python Write a while loop code where it always starts form 2. Then it...
Code in python Write a while loop code where it always starts form 2. Then it randomly chooses a number from 1-4. If the number 4 is hit then it will write “TP” if the number 1 is hit then it will write”SL”. It will rerun the program every time the numbers 1 and 5 are hit. The code should also output every single number that is randomly chosen. 2 of the same numbers can't be chosen back to back...
In python Write the code to ask a user to enter a number in the range...
In python Write the code to ask a user to enter a number in the range of 1-100. Have the code checked to make sure that it is in this range. If it is not, let the user re-enter the number. The user should be able to re-enter numbers until the number is within the correct range.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT