I have a program which prints the first letter of songs and their artists and you have to guess the song.
I want the songs to be randomly selected, but only displayed once and I want the game to end once all the songs in the list have been displayed.
Here is an example of my text file 'songs.txt':
Billie Eilish - When The Party Is Over
Ariana Grande - boyfriend
TMC - No Scrubs
Destiny's Child - Say My Name
Adele - Hello
Katy Perry - California Girls
BTS - Home
Here is my output:
The first letter of the song is: H and the artist is: BTS
Here is my code:
import random
def random_line(songs):
lines = open(songs).read().splitlines()
return random.choice(lines)
random =(random_line('songs.txt'))
artist = (random.split(' - ')[0])
song = (random.split(' - ',1)[1])
song_letter = song[0]
print ("The first letter of the song is: " + song_letter + " and the artist is: " + artist)