Question

In: Computer Science

PYTHON PROGRAM Requirements: 1. Create an empty directory a variable named song_search 2. Repeatedly prompt the...

PYTHON PROGRAM

Requirements:

1. Create an empty directory 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

3. 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 a entry with that word as the key and a list (initially empty) as the value

4. 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’ ]}

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 key word as the key

5. If the keyword the user entered is in more than one song title, print each song title on a separate line preceeded by a number beginning with one and increasing by one for each song

6. If the keyword the user entered is in none of the song titles print the message Keyword not found in any song titles

Solutions

Expert Solution

song_search={}#SONG DICTIONARY

#SONG INSERTION IN DICTIONARY
n=int(input("Press 1 to enter more songs and 0 to exit : "))
while(n):
song=input("Enter song name : ").split(" ")
for i in range(0,len(song)):
s=[]
s[0:len(song)]=[' '.join(song[0:len(song)])]#JOINS THE WORDS OF LIST ' song' AS SONG NAME.
if song[i] in song_search.keys():#IF KEY ALREADY EXIST ADDING THE SONG IN VALUE OF KEY
s=s+song_search.get(song[i])
song_search.update({song[i]:s})
else:
song_search.update({song[i]:s})
n=int(input("Press 1 to enter more songs and 0 to exit : "))


#SEARCH SONG
n=int(input("\npress 1 to search for a song and 0 to exit : "))
while(n):
song=input("Enter the keyword : ")
if song in song_search.keys():
for i in range(0,len(song_search[song])):
print(i+1," : ",song_search[song][i])
else:
print("key word not found.\n")
n=int(input("press 1 to search for a song and 0 to exit : "))


#OUTPUT-

#THANKYOU


Related Solutions

Implement a python program in file named tarvel.py. Create an empty dictionary named responses. Implement while...
Implement a python program in file named tarvel.py. Create an empty dictionary named responses. Implement while loop to take in user's name and desired destination for as long as there are user inputs. Prompt user to input yes to continue and no to quit. Prompt for user's name. Receive the name into the program and save it as the value of name variable. Prompt user for their desired vacation destination. Receive response and save it as the value of a...
python Create a file named sales_bonus.py 2. Prompt the user for the amount of sales made,...
python Create a file named sales_bonus.py 2. Prompt the user for the amount of sales made, convert to a float, and assign to sales. 3. Prompt the user for number of days missed, covert to an int, and assign to days_missed 4. If the user have more than 3000 of sales and has missed less than or equal to two days of work, assign bonus to 100. 5.   Else if the user have more than 3000 of sales or has missed...
Create a Linear Program solver using Matlab or Python. Prompt variable and constraint entry.
Create a Linear Program solver using Matlab or Python. Prompt variable and constraint entry.
Using Python, write a program named hw3a.py that meets the following requirements: Create a dictionary called...
Using Python, write a program named hw3a.py that meets the following requirements: Create a dictionary called glossary. Have the glossary include a list of five (5) programing words you have learned in chapters 4-6. Use these words as keys to your dictionary. Find the definition of these words and use them as the values to the keys. Using a loop, print each word and its meaning as neatly formatted output. Create three dictionaries called person. Have each of the person...
Create a python program that will: prompt a user for a command Command get_data Level 1:...
Create a python program that will: prompt a user for a command Command get_data Level 1: Take one of the commands my_max my_min my_range my_sum mean median mode fib factorize prime Requirements: Your commands should be case-insensitive You should use python lists to store data You should NOT use built-in python math functions, or math libraries to compute these values Tips: Write one function that will convert a string with comma-separated numbers into a python list with the numbers. You...
Description of the Assignment: Write a Python program to (a) create a new empty stack. Then,...
Description of the Assignment: Write a Python program to (a) create a new empty stack. Then, (b) add items onto the stack. (c) Print the stack contents. (d) Remove an item off the stack, and (e) print the removed item. At the end, (f) print the new stack contents: Please use the following comments in your python script: # ************************************************* # COP3375 # Student's full name ( <<< your name goes here) # Week 8: Assignment 1 # ************************************************* #...
UNIX/LINUX SCRIPT: Create a named directory and verify that the directory is there by listing all...
UNIX/LINUX SCRIPT: Create a named directory and verify that the directory is there by listing all its contents. Write a shell script to validate password strength. Here are a few assumptions for the password string.   Length – a minimum of 8 characters. • Contain alphabets , numbers , and @ # $ % & * symbols. • Include both the small and capital case letters. give a prompt of Y or N to try another password and displays an error...
2. Create a new project named named lab5_2. You will prompt the user for an amount...
2. Create a new project named named lab5_2. You will prompt the user for an amount of names to enter, and then ask for that amount of names. You’ll store these names in a vector of strings. Then you’ll sort the vector. Finally, you’ll print the results. How many names?: 4 Enter a name: Leonardo Enter a name: Donatello Enter a name: Michelangelo Enter a name: Raphael ==================== Alphabetized ==================== Donatello                  Leonardo Michelangelo                      Raphael
The requirements for this program are as follows: Create a header file named “Employee.h”. Inside this...
The requirements for this program are as follows: Create a header file named “Employee.h”. Inside this header file, declare an Employee class with the following features: Private members a std::string for the employee’s first name a std::string for the employee’s last name an unsigned int for the employee’s identification number a std::string for the city in which the employee works Public members A constructor that takes no arguments A constructor that takes two arguments, representing: the employee’s first name the...
Create a program using python that provides a simple calculator: Requires a login with a prompt...
Create a program using python that provides a simple calculator: Requires a login with a prompt for a username and a password prior to using the calculator If username and password are incorrect, the program should re-prompt to re-enter correct username and password Once logged in, the user should have access to the calculator and should have the ability for the following mathematical operators: Addition Subtraction Multiplication Division Square Root PI Exponents
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT