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

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...
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...
Write a Python program to (a) create a new empty stack. Then, (b) add items onto...
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:
Using Python, write a program named hw3b.py that meets the following requirements: Welcome the user to...
Using Python, write a program named hw3b.py that meets the following requirements: Welcome the user to Zion's Pizza Restaurant and ask the user how many people are in their dinner group. If the answer is more than eight (8), print a message saying they'll have to wait for a table. Otherwise, report that their table is ready and take their order. Assume the client orders one pizza, and ask what he/she would like on their pizza, include a loop that...
Write a program that contains 2 functions. Program will call a function named calc_commission that prompt...
Write a program that contains 2 functions. Program will call a function named calc_commission that prompt the user to enter the sales amount and computes and prints with a description the commission paid to salesperson as follows: 10% for sales amount less than $2,000.00, 15% for sales amount less than $10,000.00 and 20% for sales amount less than $20,000.00, then function calc_commission calls another function name assign_base_salary() to ask the user to enter each of 5 salesperson’s base salary ,...
Create a function named getCreds with no parameters that will prompt the user for their username...
Create a function named getCreds with no parameters that will prompt the user for their username and password. This function should return a dictionary called userInfo that looks like the dictionaries below: # Administrator accounts list adminList = [ { "username": "DaBigBoss", "password": "DaBest" }, { "username": "root", "password": "toor" } ] Create a function named checkLogin with two parameters: the userInfo and the adminList. The function should check the credentials to see if they are contained within the admin...
Write a python program using the following requirements: Create a class called Sentence which has a...
Write a python program using the following requirements: Create a class called Sentence which has a constructor that takes a sentence string as input. The default value for the constructor should be an empty string The sentence must be a private attribute in the class contains the following class methods: get_all_words — Returns all the words in the sentence as a list get_word — Returns only the word at a particular index in the sentence Arguments: index set_word — Changes...
Create a program that will prompt me for each of the following items: 1. Date of...
Create a program that will prompt me for each of the following items: 1. Date of Birth 2. Typical wake up time 3. Next Dentist Appointment. ( Date and Time) Create a Date structure and a method to load and return the date structure. Create a Time-of-day structure and a method to load and return the Time-of-day structure. Create a DateTime structure that includes the Date and Time-Of-Day structure. The Date structure should include year, month, day. The Time-of-day structure...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT