Question

Python -  Compose a program script that accepts input for album data for 3 albums including Artist,...

Python -  Compose a program script that accepts input for album data for 3 albums including Artist, Title, and exactly five track titles. Collect these into a dictionary of dictionaries structure, stores the result in a JSON file and then reads the records and displays them in tabular form with column headings.

Input

Output

Artist – The Beatles
Title – Abbey Road

Number of Tracks - 0

Artist: The Beatles    Title: Abbey Road

Artist – The Beatles

Title – Revolver

Number of Tracks – 5

Track 1 – Taxman

Track 2 - Eleanor Rigby

Track 3 - I’m Only Sleeping

Track 4 - Love You To

Track 5 – Yellow Submarine

Artist: The Beatles    Title: Revolver

   Taxman

   Eleanor Rigby

   I’m Only Sleeping

   Love You To

   Yellow Submarine

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE:

def toJSON():
    # count to keep track of number of objects
    count = 0
    # child object
    d = {}
    # take user input artist
    artist = input("Artist - ")
    # take user input title
    title = input("Title - ")
    # take user input number of tracks
    num = int(input("Number of Tracks - "))
    # insert in dictionary
    d['Artist'] = artist
    d['Title'] = title
    d['Number of Tracks'] = num
    # stores tracks
    t = []
    for i in range(0, num):
        track = input("Track " + str(i+1)+" - ")
        # append track in array
        t.append(track)
    # store it in the dictionary
    d['Tracks'] = t
    # now store the whole object in result dictionary
    # print(d)
# return the result dictionary
    return d


def JSONtoTable(obj):
    # printing its attributes
    print("Artist: ", obj['Artist'],end="  ")
    print("Title: ", obj['Title'])
    # if it has tracks print them too
    for j in range(obj['Number of Tracks']):
        print(obj['Tracks'][j])
    # line change
    print()

# call functions
res=toJSON()
JSONtoTable(res)

OUTPUT:

Please upvote if you like my answer and comment below if you have any queries or need any further explanation.

Add a comment
Know the answer?
Add Answer to:
Python -  Compose a program script that accepts input for album data for 3 albums including Artist,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT