Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def openFile(filename):
- data = []
- with open(filename,"r") as a:
- data = a.read()
- data = data.split("\n")
- return(data)
- def dictFromFile(filename):
- albums = {}
- data = openFile(filename)
- for i in range(len(data)):
- album,artist,songs,price = data[i].split("|")
- songs = songs.split(",")
- albums[album] = [artist,songs,price]
- return(albums)
- class albumInfo():
- def __init__(self,album,artist,songs,price):
- global totalCost
- self.album = albumName
- self.artist = artist
- self.songs = songs
- self.price = price
- totalcost = totalcost + self.price
- def addDict(self,albums):
- albums[self.album] = [self.artist,self.songs,self.price]
- def searchDict(dictionary,find):
- for key in dictionary.items():
- if find in dictionary[key][0]:
- print("Found {} in Album:{}".format(find,key))
- return
- print("Did not find your song :(")
- def run():
- albums = infoFromFile("info.txt")
- keepGoing = True
- while keepGoing:
- ask = (input("Enter: A=Add Song, S=Search for a Song, T=Returns Total Value of Songs, Q=Quit Program")).upper()
- if ask in ["A","S","T","Q"]:
- if ask == "T":
- print(totalCost)
- elif ask == "S":
- find = input("What song do you want to find?")
- searchDict(albums,find)
- elif ask == "A":
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement