Advertisement
dmesticg

Untitled

Apr 19th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. def openFile(filename):
  2. data = []
  3. with open(filename,"r") as a:
  4. data = a.read()
  5. data = data.split("\n")
  6. return(data)
  7.  
  8. def dictFromFile(filename):
  9. albums = {}
  10. data = openFile(filename)
  11. for i in range(len(data)):
  12. album,artist,songs,price = data[i].split("|")
  13. songs = songs.split(",")
  14. albums[album] = [artist,songs,price]
  15. return(albums)
  16.  
  17. class albumInfo():
  18. def __init__(self,album,artist,songs,price):
  19. global totalCost
  20. self.album = albumName
  21. self.artist = artist
  22. self.songs = songs
  23. self.price = price
  24. totalcost = totalcost + self.price
  25.  
  26. def addDict(self,albums):
  27. albums[self.album] = [self.artist,self.songs,self.price]
  28.  
  29. def searchDict(dictionary,find):
  30. for key in dictionary.items():
  31. if find in dictionary[key][0]:
  32. print("Found {} in Album:{}".format(find,key))
  33. return
  34. print("Did not find your song :(")
  35.  
  36.  
  37. def run():
  38. albums = infoFromFile("info.txt")
  39. keepGoing = True
  40. while keepGoing:
  41. ask = (input("Enter: A=Add Song, S=Search for a Song, T=Returns Total Value of Songs, Q=Quit Program")).upper()
  42. if ask in ["A","S","T","Q"]:
  43. if ask == "T":
  44. print(totalCost)
  45. elif ask == "S":
  46. find = input("What song do you want to find?")
  47. searchDict(albums,find)
  48. elif ask == "A":
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement