I am creating a music quiz. Below is my CSV file. I would like to select a song and artist at random from the file - displaying the artist name but only the FIRST LETTER of each word in the song name to be displayed.
I was wondering if any of you knew how I could do this on Python. The file name is called playlist.csv
I have tried several different methods such as the one below, but it does not work.
with open('playlist.csv') as mycsv:
print(mycsv.readline()[0])
I've already imported CSV file and stored artists and songs in CSV file.
Songs Artists
Maroon 5 Girls Like You Andrea Garcia
I Like It Cardi B
God's Plan Drake
No Tears Left To Cry Ariana Grande
Psycho Post Malone
The Middle Maren Morris
Better Now Post Malone
In My Feelings Drake
It's Coming Home The Lightning Seeds
One Kiss Dua Lipa
A random song and artist is chosen.
For example:
M, Andrea Garcia
G, Drake
B, Post Malone
O, Dua Lipa.
At the moment, I am also trying to create an if statement where, if the user's guess for the randomly generated song is correct, they get a message saying "Correct answer". This is what I've attempted at the moment.
userName = str
password = str
userName = raw_input("What is your name?")
password = raw_input("Please enter the correct password.")
if userName == "John" or "John" or password!= "musicquiz":
print("Sorry, the username is taken and/or the password is incorrect.")
quit()
if userName!= "John" and password == "musicquiz":
print("Hello", userName, "welcome to the game!")
import random
with open('playlist.csv') as mycsv:
f=mycsv.readlines()[1:]
random_line=random.choice(f).split(',')
print(random_line[0][0],",",random_line[3])
userGuess = str
userScore = int
userScore = 0
userGuess = raw_input("What is the correct name of this song?")
if userGuess == true:
print("Well done, that was the correct answer. You have scored three points")
userScore + 3
else:
print("Sorry, your guess was incorrect. You have one more chance to guess it right")
raw_input("What is the correct name of this song?")
if userGuess != true:
print("Sorry, game over.")
quit()
if userGuess == true:
print("Well done, that was the correct answer. You scored one point.")
userScore + 1