top of page

Data Scientist Program


Free Online Data Science Training for Complete Beginners.

No prior coding knowledge required!

Song Picker Program using Python

This simple python program aims at taking the users' preference of genre then recommending a random song to listen to from this genre.


print('what genre do you prefer ?')
user_pick = input().casefold()

This part prints a question to the user and receives the answer in the form of string. The casefold here ignores the entry of capital or small letters in the input.

In the next lines of code we define the songs under each genre as a list.

blues = ['I Cant Quit You Baby – Otis Rush.' , 
"I'd Rather Go Blind – Etta James." ,
'Crossroad Blues – Robert Johnson.' ,
'Pride and Joy – Stevie Ray Vaughan.', 
"I'm Tore Down – Freddy King. " ,
"Born Under A Bad Sign – Albert King." ,
'Sunshine of Your Love – Cream.' , 
'Hoochie Coochie Man – Muddy Waters.' ]
jazz = ["All The Things You Are." , 
"Georgia On My Mind.",
"Body and Soul.",
"Fly Me to the Moon." ,
"Night and Day."] 
rock = ["Skullcrusher", 
"Spirit of the Beehive", 
"For Your Health", 
"Wolf Alice"]
country = ["I Walk the Line" ,
"Jolene" ,
"Friends in Low Places", 
"Choices" ,
"Concrete Angel" ,
"Kiss an Angel Good Morning" ,
"Where Were You",
"Live Like You Were Dying" ]

dance = ["We Are Family" ,
"The Hustle",
"I Will Survive" ,
"Thank You"]

genre = ["blues", "jazz" , "rock" , "country" , "dance"]

In the next section we import random method and use a for loop to match the user's input with the song outcome. The random.choice chooses a random song from the genre list chosen by the user.

If the user chose a genre that is not listed the function prints "pick another genre".

import random
i = user_pick
for i in genre :
    if user_pick == "blues":
        blues_song = random.choice(blues)
    elif user_pick == "jazz" :
        jazz_song = random.choice(jazz)
    elif user_pick == "rock" :
        rock_song = random.choice(rock)
    elif user_pick == "country":
        country_song = random.choice(country)
    elif user_pick == "dance" :
        dance_song = random.choice(dance)
        print("pick another genre")
1 comment

Recent Posts

See All

1 comentário

Data Insight
Data Insight
20 de set. de 2021

Very Nice!

bottom of page