Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The data file provided (zypas.dat) gives the list of artists and the number of units of music they've sold in the following format Phil Collins

image text in transcribed

The data file provided (zypas.dat) gives the list of artists and the number of units of music they've sold in the following format Phil Collins 33.5 million units Britney Spears34 million units Bon Jovi 34.5 million units Queen 34.5 million units Def Leppard 35 million units You will need to do the following: . Assign the file that you've inputted and opened to a file name, because this is zyBooks, use the command: filename - open ('zypa8.dat', 'r') .Initialize a dictionary . Read each line of the input file using either (or try it both ways, commenting out one; do they give the same result?): for line in filename.readlines) or for line in file: . Each line will be a string, e.g., 'Phil Collins-33.5 million units . You can use the string method split0 to make this into a list with two string items Furthermore, you can use splito again to isolate the number, e.g, 33.5, from one of the strings (DO THIS CAREFULLY OR YOULL END UP WITH A MESS. THIS IS WHERE MOST STUDENTS MESS UP I!!) You can then nest float0, round0, and int0 and use the result together with the method for adding items to dictionaries to add each key- value pair from a line to the dictionary; use stripO to remove any unwanted whitespace . After you've created your dictionary, you can use another for-loop to print out the key-value pairs . To make it look nice, use format specifiers: print( (0: 35) (1) .format (key name, (value_name 75)) Finally, don't forget the comment about the 5 million units and close your file 0/25 LAB ACTVITY 13.7.1: Best-Selling Musicians zypa8.py 1 filename open('zypa8.dat', r)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Heikki Topi, Jeffrey A Hoffer, Ramesh Venkataraman

13th Edition

0134773659, 978-0134773650

More Books

Students also viewed these Databases questions

Question

How is a year-over-year percentage calculated?

Answered: 1 week ago