The text file is formatted like so: artist, title, genre, play length, condition, stock, cost
the text file contains records of many genres which i need to add to a dictionary and count how many there are.
this is my code however when i run it, it returns 0 for each genre
def count_genres():
file = open("RECORD_DATA.txt", 'r')
rock = 0
classical = 0
pop = 0
jazz = 0
spoken_word = 0
for row in file:
if not row[0] == "#":
row = row.rstrip()
row = row.split(",")
genre = str(row[2])
if genre == "Rock":
rock += 1
elif genre == "Classical":
classical += 1
elif genre == "Pop":
pop += 1
elif genre == "Jazz":
jazz += 1
elif genre == "Spoken Word":
spoken_word += 1
print("Amount of Records in each genre ")
print("Rock: ", rock)
print("Classical: ", classical)
print("Pop: ", pop)
print("Jazz: ", jazz)
print("Spoken Word: ", spoken_word)