The document describes creating a Python script to take song data as input and store it in a text file. The script takes in a song title, its highest chart placement, and band members and their instruments. It stores this information for each song entered and can print out all the stored data from the text file. The script uses loops and file input/output methods to repeatedly collect song data and write it line by line to a text file, then read and print the entire contents of the file.
I am trying to create a python script and need a little help.Im tr.pdf
1. I am trying to create a python script and need a little help.
Im trying to write a program that will take 3 inputs and store in a text file. Input one will be a
song title, two will be its highest place on the charts and three will be band memebrs and their
instruments.
The output Im trying to get is I want to do this for as many songs as I want to enter, and then be
able to print all that data from the txt file.
Solution
# i provided this solution earlier it had indentaion problem, not this solution is working perfectly
fine.
#=======code=================
#you might get intendation error in your system.
entering=True
while entering:
name = input("Song Name?")
chart= input("hights place on charts")
addmember=True
mem = [] #member list, to add required number of member.
while addmember :
member=input("enter member");
instrument=input("enter instrument");
mein=member+' '+instrument;
mem.append(mein) #appending members in list.
moremembers=int(input("press 1 to stop adding members"))
if moremembers==1:
addmember=False
fd = open("songsfile.txt","w")
fd.write(name)
fd.write(' ')
fd.write(chart)
fd.write(' ')
fd.write(' '.join(mem))
fd.close()
2. moresongs=int(input("press 1 to stop adding songs"))
if moresongs==1:
entering=False
f = open("songsfile.txt","r")
contents = f.read()
f.close()
print (contents)