Mastering Development

Python function and if…else

The goal is to create a function to receive any word as input, search songs only, and return the number of top songs that contain that word. The function should be able to receive and word/phrase as an input string and return a message (i included one in my code); if the word/phrase is not found, it must return a message saying no songs were found with "word/phrase;" has to be able to deal with upper/lower case letters. At the end, I have to test the function with the word "like," which should result in 100 songs.

Data set:

My code is:

def no_top_songs(word):
    for song in lyrics['Song']:
        if word in lyrics:
        if count!=0:
            print(f'{str(count)} songs were found to contain {word} in this dataset')
            print(f'No songs were found to contain the words:{word}')

Output is hundreds of rows of "No songs were found to contain the words:like" and then one row of "None"

Please help. I am not sure what I am doing wrong.

Leave a Reply

Your email address will not be published. Required fields are marked *