Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- albumdict = {}
- albumname = ""
- songlist = None
- cost = None
- artistname = ""
- filename = "gg.txt"
- mydict = {}
- class musicLibrary(dict):
- def __init___(self,dict1):
- ## self.dictionary = {}
- ## self.dictionary = dict1
- self.sumofcost = 0
- self.__dict__ = dict1
- @staticmethod
- def totalCost(dic):
- sumofcost=0
- for key in dic:
- sumofcost += float(dic[key][1][1])
- return(sumofcost)
- @staticmethod
- def searchSong(mydict):
- value = input("Search a song to find more information about it")
- for key,val in mydict.items():
- if value in mydict[key][0]:
- print(value,"in album:",key,"by",mydict[key][1][0],mydict[key][1][2],"cost:",mydict[key][1][1])
- def formatFile(file,dictionary):
- with open(file) as f:
- key = []
- songinfo = []
- for line in f:
- line = line.strip()
- a = line.split(",")
- b = line.split("/")
- if "" in b:
- key.append(b[1])
- elif "" in a:
- songinfo.append(a)
- for i in range(len(songinfo)):
- songinfo[i].remove("")
- for i in range(len(key)):
- dictionary[key[i]] = [songinfo[i*2],songinfo[(i*2)+1]]
- print(dictionary)
- return(dictionary)
- def addSong(thefile):
- albuminput = input("Enter Album Name:")
- songinput = input("Enter Song Names seperated with commas")
- songinfoinput = input("Enter Artist name, price, and year in that order(seperated by commas)")
- file =open(thefile,"a")
- file.write("\n"+"/"+albuminput)
- file.write("\n"+","+songinput)
- file.write("\n"+","+songinfoinput)
- file.close
- def userInput(mydict):
- valid = True
- while valid:
- userinput = input("Enter S to search for a song, A to see the value of your collection, E to enter songs into your collection, Q to quit").upper()
- if userinput == "Q":
- valid =False
- if userinput == "S":
- musicLibrary.searchSong(mydict)
- if userinput.upper() =="A":
- cost=musicLibrary.totalCost(mydict)
- print("The cost of your collection is","$",cost)
- if userinput == "E":
- addSong(filename)
- userInput(formatFile(filename,mydict))
- FILE:
- /?
- ,Moonlight,Sad!,Hope,Infinity 888,Angel
- ,x,9.99,2018
- /Love_letter_to_you
- ,Love Scars,Blade of Woe,Romeo&Juliet
- ,Trippie Redd,8.99,2017
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement