Kristina D.

asked • 10/21/20

Creating a Song Search Program with Python

Could someone help? I need to


  1. Create an empty dictionary a variable named song search
  2. Repeatedly prompt the user to enter either the title of a song or enter nothing if they have no more songs to enter. For each song title entered by the user, split the song title into words by using the split function and splitting on a space. For each word from each song title, ensure the song_search dictionary has an entry with that word as the key and a list (initially empty) as the value.
  3. Also for each song title entered by the user and each word from each song title, insert the full song title into the list inside the song_search dictionary associated with each of the words from the song. For example, the contents of the song_search dictionary after the user would have entered the song titles Crazy in Love and What is Love:

song_search = {

'Crazy" : [ 'Crazy in Love' ] ,

'in' : [ 'Crazy in Love' ] ,

'Love' : [ 'Crazy in Love' , 'What is Love' ] ,

'What' : [ 'What is Love' ] ,

'is' : [ 'What is Love' ]

}


  1. Once the user has finished entering song titles, repeatedly ask the user if they want to look up a song by keyword until they say no. If they respond yes prompt them for a keyword and print all the song titles containing that word by looking up the value in the song_search dictionary using the keyword as the key.
  2. If the keyword the user entered is more than one song title, print each song title on a separate line proceeded by a number beginning with one and increasing by one for each song.
  3. If the keyword the user entered is in none of the song titles, print the message Keyword not found in any song titles

EXAMPLE:

Welcome to my song search program.

Enter the name of a song title, or enter nothing and press Return when done.

What is Love

Enter the name of a song title, or enter nothing and press Return when done.

Crazy in Love

Enter the name of a song title, or enter nothing and press Return when done.


Would you like to lookup a song by keyword (yes/no)? yes

Enter keyword: Love

  1. What is Love
  2. Crazy in Love

Would you like to lookup a song by keyword (yes/no)? yes

Enter keyword: What

  1. What is Love

Would you like to lookup a song by keyword (yes/no)? yes

Enter keyword: Insane

Keyword not found in any song titles

Would you like to lookup a song by keyword (yes/no)? no

Thanks for using the song search program.

2 Answers By Expert Tutors

By:

Stephen D. answered • 10/21/20

Tutor
5 (9)

Software Engineer Specializing in C++

Patrick B. answered • 10/22/20

Tutor
4.7 (31)

Math and computer tutor/teacher

Stephen D.

This response does not correctly reflect the question.
Report

10/22/20

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.