Advertisement
Skuxxx

Untitled

Apr 23rd, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. albumdict = {}
  2. albumname = ""
  3. songlist = None
  4. cost = None
  5. artistname = ""
  6. filename = "gg.txt"
  7. mydict = {}
  8.  
  9. class musicLibrary(dict):
  10. def __init___(self,dict1):
  11. ## self.dictionary = {}
  12. ## self.dictionary = dict1
  13. self.sumofcost = 0
  14. self.__dict__ = dict1
  15.  
  16. @staticmethod
  17. def totalCost(dic):
  18. sumofcost=0
  19. for key in dic:
  20. sumofcost += float(dic[key][1][1])
  21.  
  22. return(sumofcost)
  23. @staticmethod
  24. def searchSong(mydict):
  25. value = input("Search a song to find more information about it")
  26. for key,val in mydict.items():
  27. if value in mydict[key][0]:
  28. print(value,"in album:",key,"by",mydict[key][1][0],mydict[key][1][2],"cost:",mydict[key][1][1])
  29.  
  30.  
  31. def formatFile(file,dictionary):
  32. with open(file) as f:
  33. key = []
  34. songinfo = []
  35. for line in f:
  36. line = line.strip()
  37. a = line.split(",")
  38. b = line.split("/")
  39. if "" in b:
  40. key.append(b[1])
  41.  
  42. elif "" in a:
  43. songinfo.append(a)
  44. for i in range(len(songinfo)):
  45. songinfo[i].remove("")
  46.  
  47. for i in range(len(key)):
  48. dictionary[key[i]] = [songinfo[i*2],songinfo[(i*2)+1]]
  49. print(dictionary)
  50. return(dictionary)
  51.  
  52. def addSong(thefile):
  53. albuminput = input("Enter Album Name:")
  54. songinput = input("Enter Song Names seperated with commas")
  55. songinfoinput = input("Enter Artist name, price, and year in that order(seperated by commas)")
  56.  
  57. file =open(thefile,"a")
  58. file.write("\n"+"/"+albuminput)
  59. file.write("\n"+","+songinput)
  60. file.write("\n"+","+songinfoinput)
  61. file.close
  62.  
  63. def userInput(mydict):
  64. valid = True
  65.  
  66. while valid:
  67. 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()
  68. if userinput == "Q":
  69. valid =False
  70.  
  71. if userinput == "S":
  72. musicLibrary.searchSong(mydict)
  73. if userinput.upper() =="A":
  74.  
  75. cost=musicLibrary.totalCost(mydict)
  76. print("The cost of your collection is","$",cost)
  77.  
  78. if userinput == "E":
  79. addSong(filename)
  80.  
  81.  
  82. userInput(formatFile(filename,mydict))
  83.  
  84. FILE:
  85.  
  86. /?
  87. ,Moonlight,Sad!,Hope,Infinity 888,Angel
  88. ,x,9.99,2018
  89. /Love_letter_to_you
  90. ,Love Scars,Blade of Woe,Romeo&Juliet
  91. ,Trippie Redd,8.99,2017
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement