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
Bas_tet [7]
3 years ago
14

Write a function to receive any word as input, search the song titles only and return the number of top billboard songs that con

tain that word. Your function should meet the following requirements: Your function should receive any word or phrase as an input string and return a simple message with the number of songs that contain those words. E.g. [5] songs were found to contain [supplied phrase] in this dataset If the words or phrase supplied were not found in the database, return the message No songs were found to contain the words: [supplied phrase] Remember to deal with whatever letter case you are supplied i.e. all caps or all lowercase, etc. Test your function with the word like and confirm that your result reads [100] songs were found to contain [like] in this dataset

Computers and Technology
1 answer:
melisa1 [442]3 years ago
8 0

Answer:

Here is the function:

def NumberOfSongs(word):  # function definition    

   count=0  #count the occurrence of word in song

   for song in lyrics['Lyrics']:  #iterates through song lyrics

       if word in str(song):  #if word is in the song

           count=count+1  #adds 1 to the count

   if count!=0:  #if word occurs in the songs

       return f'{str(count)} songs were found to contain {word} in this dataset'  #display the count of the word in the song

   else:  #if word does not appear in any song

       return f'No songs were found to contain the words:{word}'  #returns this message if no songs were found with given word

print(NumberOfSongs('like')) #calls method with the word like given as parameter to it

Explanation:

You can add the csv file this way:

import pandas as pd

lyrics = pd.read_csv("lyrics.csv", encoding="cp1252")

Now you can use the NumberOfSongs method which iterates through the Lyrics of lyrics.csv and find if any of the songs in the file contains the specified word.

The screenshot of program along with its output is attached. Since the file was not provided i have created a csv file. You can add your own file instead of lyrics.csv

You might be interested in
Define a function PrintFeetInchShort, with int parameters numFeet and numInches, that prints using ' and " shorthand. Ex: PrintF
DaniilM [7]

Answer:

The function declaration to this question as follows:

Function declaration:

//declaring method printFeetInchShort, that accepts two integer parameters

void printFeetInchShort(int numFeet,int numInches) //method

{//method body

printf("The given height is: "); // message printing

printf("%d\'%d\" ", numFeet,numInches); //value printing

}

Explanation:

In the above method (function) declaration a method "printFeetInchShort" is declared, that accepts two integer variable as its parameters.

  • This method uses a return type void, which means it will not return any value.  
  • The parameter "numFeet and numInches" accepts an integer value in the main method and inside the method, it will print its value by a single and double quote.
5 0
3 years ago
Why PS5 10.2 teraflops is better than 12 teraflops on the Xbox series x?
lara [203]

I really don't know why, but this is a website for homework related problems, not comparing the two new consoles.

<em>PS: I really don't know why.</em>

7 0
3 years ago
Pls can anyone be so kind and answer this question.....i need the answer urgently
mixas84 [53]

Answer:

so u have to be smaet

Explanation:

8 0
3 years ago
Which Traffic Source dimensions does Google Analytics automatically capture for each user who comes to your site?A. Source, Keyw
LenaWriter [7]

For each user who comes to your site the google analytics automatically capture the traffic source dimensions Source, Medium, Campaign name.

<u>Explanation:</u>

Source:

  • There cannot be any reference to a website without an origin source.
  • The source is basically the origin of your traffic such as a search engine (google) or a domain (ex: Twitter).

Medium:

  • Every referral to a website also has a medium along with the source.
  • examples are -:  unpaid search, "cost per click", referral, mail.

Campaign name:

  • The campaign Name is the name referring to the google ads campaign.
5 0
4 years ago
Write a program that divides mystery_value by mystery_value #and prints the result. If that operation results in an #error, divi
Zolol [24]

Answer:

mystery_value = 5  

try:

   print(mystery_value / mystery_value)

except:

   try:

       print(mystery_value / (mystery_value + 5))

   except:

       print(mystery_value * 5)

5 0
3 years ago
Other questions:
  • The main difference between a lan, a man, and a wan is _____. the ability to connect to the internet the geographic area they co
    8·1 answer
  • The e-mail address of any third party recipient of an e-mail belongs in which field?
    8·1 answer
  • Which of these statements about symmetric key encryption is true? The file is encrypted with a private key and can be decrypted
    14·1 answer
  • to _________________________ is a mouse operation in which you move the mouse until the pointer on the desktop is positioned on
    7·1 answer
  • An invisible path determining the way of travel from one place to another.
    10·1 answer
  • What role do computer play in law and order​
    6·1 answer
  • Identify the final stage of the object found in the image in the given text
    9·1 answer
  • Can any one help me please with my computer science hwk :)
    11·1 answer
  • Have you heard about Gold Opinions?<br><br> It is a new product that just came out.
    6·1 answer
  • Please describe the role of games in modern society!
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!