1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Semmy [17]
4 years ago
8

Write a program that takes nouns and forms their plurals on the basis of these rules:

Computers and Technology
1 answer:
soldi70 [24.7K]4 years ago
4 0

Answer:

def nounToplural(tex):

   import re

   

   text = tex.split()

   new = []

   for word in text:

       if re.findall(r"y\b", word):

           word = re.sub(r"y\b", 'ies' ,word)

           new.append(word)

       

       elif re.findall(r"ch\b", word):

           word = re.sub(r"ch\b", 'ches' ,word)

           new.append(word)

       elif re.findall(r"sh\b", word):

           word = re.sub(r"sh\b", 'shes' ,word)

           new.append(word)

       elif re.findall(r"s\b", word):

           word = re.sub(r"s\b", 'ses' ,word)

           new.append(word)

       else:

           word = word + 's'

           new.append(word)

   result = []

   for i in text:

       for j in new:

           if new.index(j) == text.index(i):

               result.append( (i,j) )

           

           

   print(result)

str = "chair dairy boss circuis fly dog church clue dish"

nounToplural(str)

Explanation:

We made use or Regular Expressions which is simply a special sequence of characters that helps you match or find other strings or sets of strings, by using a specialized syntax held in a pattern.

Firstly, define the function and import the regular expression module, split the text into a list and create an empty list to hold the plural list.

For every word in the list  we check with IF statements and regular expressions to find out what they end with.

 if re.findall(r"y\b", word):

           word = re.sub(r"y\b", 'ies' ,word)

           new.append(word)

The above IF block checks if a noun ends with 'y', if it does it replaces the 'y' with 'ies' and ads it to the new list.

If it does not, ot moves to the next IF/ELIF block.

In the ELIF blocks carry out a  a similar operation for "s", "ch", or "sh", in order to add "es".

Finally, 's' is added to all other cases using the ELSE block which traps any noun that did not fall under the IF or any of the ELIF blocks.

This last part of the code prints both list side by side and passes them to a new list result which is printed to the screen

<em>result = [] </em>

<em>    for i in text: </em>

<em>        for j in new: </em>

<em>            if new.index(j) == text.index(i): </em>

<em>                result.append( (i,j) ) </em>

<em>             </em>

<em>             </em>

<em>    print(result)</em>

I called the function and passed the string you provided in your question and attached the result of the code.

You might be interested in
Lots of Ways to Use Math.random() in JavaScript
Alja [10]

Math.random() is a built-in function in JavaScript that generates a random number between 0 and 1.

<h3>What is Math.random()?</h3>

Math.random() is a useful and versatile function that can add a element of randomness to your JavaScript programs.

This function can be used in a variety of ways in JavaScript programs, such as:

  1. Generating random numbers for games or simulations.
  2. Creating random samples for statistical analysis.
  3. Shuffling elements in an array for a random order.
  4. Selecting random items from a list for a quiz or survey.
  5. Creating unique IDs or keys for objects in a database.

To Know More About built-in function, Check Out

brainly.com/question/29796505

#SPJ4

8 0
1 year ago
Four categories of installer apps
Naddika [18.5K]

Answer:

I find 5 categories

Explanation:

1 Overview

2 Necessity

3 Types

4 Attended installation

4.1 Silent installation

4.2 Unattended installation

4.3 Headless installation

4.4 Scheduled or automated installation

4.5 Clean installation

4.6 Network installation

5 Installer

5.1 Bootstrapper

5.2 Common types

5.3 System installer

7 0
3 years ago
The mode is least appropriate for:___________
bazaltina [42]

Answer:

Your question seems incomplete

Explanation:

7 0
3 years ago
When 2 or more computers are connected it is called?
Alenkasestr [34]

When two or more computers are connected it is called Local Area Network (LAN).

5 0
3 years ago
Compiler software has a stepping function that
just olya [345]

Answer:

Runs code line by line to help developers find bugs.

Explanation:

I took the test.

3 0
3 years ago
Read 2 more answers
Other questions:
  • Search the internet for news of a motor vehicle collision in your community involving drugs or alcohol. Keeping in mind that you
    15·1 answer
  • A bookmarking site is a website that enables members to manage and share media such as photos, videos, and music. true or false
    14·1 answer
  • What identifies available computers through the internet?
    14·1 answer
  • Can someone help me with...A table can help? PLEASE
    8·1 answer
  • The mathematical constant Pi is an irrational number with value approximately 3.1415928... The precise value of this constant ca
    12·1 answer
  • What are the pros and cons of using a linked implementation of a sparse matrix, as opposed to an array-based implementation?
    11·1 answer
  • Create a program with a script that calls the following functions: getinput, calculateGPA, createBor, and printResults. The prog
    6·1 answer
  • Jennifer stays fit by playing games that track the movement of her body. Which platform features such a physical interface featu
    15·1 answer
  • What are the different Stape of data processing cycle?​
    8·1 answer
  • The capital letter Wis expressed as U+0057 in which system?
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!