Question

In: Computer Science

You are a songwriter, tired and upset because of all the lame easy rhymes that are...

You are a songwriter, tired and upset because of all the lame easy rhymes that are in the most popular songs today. You decide to write a program that checks if two words rhyme. The program ignores and discards perfect rhymes such as rat and bat or glove and dove. The program returns a rhyme percentage based on the pronunciation of the words.

Because the program ignores perfect rhymes, words that rhyme perfectly will receive a score higher than a certain amount. If a pair of pronunciations receive a score of 75% or higher, it is considered a perfect rhyme. In such a case the program must return -1. However, if the pronunciations receive a score of 40% or lower, the rhyme is too weak to use and the program must return -999. Otherwise the program must return the rhyme (percentage) score.

A rhyme score is calculated by comparing the letters of each syllable of two words:

  1. If one letter matches, that should add a score of 0 to the overall rhyme score
  2. If two consecutive letters match a score of 2 should be added to the overall rhyme score.
  3. If three consecutive letters match a score of 3 should be added, and so on.
  4. An underscore "_" represents the ending and starting of two syllables.

The rhyme score is then determined by the total score divided by the total number of letters in the largerpronunciation (excluding the underscores if any).

Write a function bRhymes() that accepts 2 pronunciations as strings and returns the rhyme percentage rounded to 1 decimal place, -1 if it is a perfect rhyme or -999 if the rhyme is too weak.

Code is already provided for the program which runs your function  bRhymes().

Input Format

[PROGRAM INPUT]

Two lines each containing a string, such as ahi_dee_uhl_ahiz (in Line 1) and ree_uhl_ahiz (in Line 2). The first line for the pronunciation of the first word and the second line for the pronunciation of the second word. An example of the exact input would appear as:

ahi_dee_uhl_ahiz

ree_uhl_ahiz

.

[FUNCTION bRhymes() INPUT]

2 strings which represents rhyme pronunciations

Constraints



where w1 and w2 are pronunciations

Output Format

[PROGRAM OUTPUT]

A single float, such as 69.2 which represents the rhyme percentage rounded to 1 decimal place, -1 if it is a perfect rhyme or -999 if the rhyme is too weak. An example of the exact output would appear as:

69.2

Solutions

Expert Solution

def bRhymes(f,s): #function definition
    f1=f.split("_")   #splitting pronounciations into lists
    f2=s.split("_")
    if len(f1)>len(f2): #finding the largest pronounciation to l1
                         #smallest tp l2
        l1=f1
        l2=f2
    else:
        l1=f2
        l2=f1
    s1=len(l1)   #finding the lenght of lists
    s2=len(l2)
    score=0
    for i in l1:  
        for j in l2:   #for every word in l1 get l2
            if len(i)<=len(j):       #if l1 word is less than l2 word
                l=0           #l to access the largest word character
                count=0      #count=0
                for k in range(len(i)):     
                    if i[k]==j[l]:   #if charatcers are equal count++
                        count=count+1
                    if(count>1):     #if more than one consecutive charatcers are equal add it to score
                        score=score+count
                    l=l+1    # l to access largest word character
            else:        #if l2 word greater than l1 word
                l=0     #l to access smallest word charatcer
                count=0
                for k in range(len(j)):
                   if j[k]==i[l]:    #if characters are equal count++
                        count=count+1
                   if(count>1):    #if more than one consecutive characters are equal add it to score
                        score=score+count
                   l=l+1
                score=score+count
    totalCharacters=0                           #finding the total characters in largest pronounciation
    for i in l1:
        totalCharacters=totalCharacters+len(i)
    score=score/len(l1)     #total score= score/ letters in largest pronounciation
    total=score/(len(l1)+len(l2))*100   #finding score percentage
    total=round(total,1)   #rounding percentage to one decimal
    if(total>=75):     #if percentage >75 rhyming is perfect so return -1
        return -1
    elif(total<=40):   #if percentage<40 rhyming is weak so return -999
        return -999
    else:           #returning the score percentage
        return total
f='ahiz_ahi_dee_uhl'
s='ree_uhl_ahiz'    
print(bRhymes(f,s))

output:

-1
   


Related Solutions

You are a supervisor in a government office. Your workers are upset because their work hours...
You are a supervisor in a government office. Your workers are upset because their work hours have recently been changed to 8:00am-4:30pm after two years of having flextime in place. Previously, employees were required to be in the office between 10:00am-2:30pm as core hours and could work the remaining part of their eight-hour day anytime between 6:00am and 7:00pm. Employees were free to manage their own time and you did not track their work hours. Everything appeared to be working...
A patient is upset because he has been placed on a special therapeutic diet because of...
A patient is upset because he has been placed on a special therapeutic diet because of his high b/p. He is concerned that he will not be successful with his diet change. How can you encourage him to follow the physicians orders to improve his health?
1. Accounting is an easy subject for people to understand because almost everyone is exposed to...
1. Accounting is an easy subject for people to understand because almost everyone is exposed to basic accounting concepts in their everyday life. True or False?? 2. Although managers who work for large firms must know something about accounting, people who run small businesses only need to know the basics of bookkeeping. True False 3. It is impossible to run a company effectively without the ability to read and understand basic accounting reports and financial statements. True False 4. With...
The stem diameter of wheat is important because easy breakage of the wheat can interfere with...
The stem diameter of wheat is important because easy breakage of the wheat can interfere with harvesting the crop. The diameter of wheat is known to be normally distributed with a mean of 1.9 mm. An agronomist hypothesizes that the new fertilizer being used is increasing plant stem diameter. After 5 days from the flowering of the wheat, the agronomist measures the diameters (mm) of the plants. What can the agronomist conclude with an α of 0.01? The wheat diameters...
This week research will be easy because the fast-food industry is one that is probably familiar....
This week research will be easy because the fast-food industry is one that is probably familiar. Have fun discussing this topic. Choose a company in the online product sales industry or an international chain in the fast-food industry. Describe the nature of the company’s international operations, its motivations, its entry strategies, the kinds of implementation problems the firm has run into, and how those problems have been dealt with. When responding to your classmates, consider what kind of constructive feedback...
Halogenated compounds are particularly easy to identify by their mass spectra because chlorine and bromine occur...
Halogenated compounds are particularly easy to identify by their mass spectra because chlorine and bromine occur naturally as mixtures of two abundant isotopes. •Chlorine occurs as 35Cl (75.8%) and 37Cl (24.2%); •Bromine occurs as 79Br (50.7%) and 81Br (49.3%); •Boron compounds also stand out owing to the two isotopes 10B (19.9%) and 11B (80.1%). For the compound Chlorocyclohexane, C6H11Cl: a) At what masses do the molecular ions occur? b) What are the percentages of each molecular ion?
26. Because of easy entry, monopolistically competitive firms will charge a price equal to their marginal...
26. Because of easy entry, monopolistically competitive firms will charge a price equal to their marginal cost earn no economic profit in the short-run earn no economic profit in the long-run produce at the lowest average total cost achieving production efficiency take advantage of all economies of scale available to it 27. Excess capacity typically occurs in the short-run in perfect competition in the long-run equilibrium in monopolistic competition in the short-run in monopolistic competition in the long-run equilibrium in...
**please put the solution in easy to understand letters because I also want to learn how...
**please put the solution in easy to understand letters because I also want to learn how to solve it, thanks 1) On a particular production line, the likelihood that a light bulb is defective is 10%. Seven light bulbs are randomly selected. What is the probability that at most 4 of the light bulbs will be defective? 2) Patients scheduled to see their primary care physician at a particular hospital wait, on average, an additional seven minutes after their appointment...
What mathematical property describes a good that you get tired of consuming as you consume more...
What mathematical property describes a good that you get tired of consuming as you consume more of it? Diminishing marginal utility Negative marginal utility Positive marginal utility Increasing marginal utility
Show all your work. Indicate clearly the methods you use, because you will be scored on...
Show all your work. Indicate clearly the methods you use, because you will be scored on the correctness of your methods as well as on the accuracy and completeness of your results and explanations. To prevent deer from running across highways, researchers are investigating sound-emitting devices that would frighten deer before they reach the highway. As part of the investigation, the researchers set up  20 devices along a two-mile stretch of road. When a deer approached a device, the device would...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT