w: write database to a file. The function name should be writeToFile with no par
ID: 3831577 • Letter: W
Question
w: write database to a file. The function name should be writeToFile with no parameter. -3 pts if a different name is used. Write to a file named, musicLibrary.txt, the contents of the database in the following format: songTitle|top10Rank|artistStageName|artistName|artistHomeTown|latestSalesAmount where songTitle is the song title top10Rank is the top 10 rank artistStageName is the song artist’s stage name artistHomeTown is the song artist’s home town latestSalesAmount is the last sales amount in the sales record – the last element in the sales record PYTHON please
Explanation / Answer
def writeToFile:
f=open("musicLibrary.txt",'a') #open the file for appending
#get data
songTitle=input("Enter Song Title : ")
top10Rank=input("Enter the top rank : ")
artistStageName=input("Enter the artist's stage name :")
artistName=input("Enter the artist's name :")
artistHomeTown=input("Enter the artist's home town :")
latestSalesAmount=input("Enter the latest sales amount :")
#write data to the file
f.write(str(songTitle)+"|"+str(top10Rank)+"|"+str(artistStageName)+"|"+str(artistName)+"|"+str(artistHomeTown)+"|"+str(latestSalesAmount)+" "
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.