Westonci.ca is the best place to get answers to your questions, provided by a community of experienced and knowledgeable experts. Our Q&A platform offers a seamless experience for finding reliable answers from experts in various disciplines. Experience the convenience of finding accurate answers to your questions from knowledgeable experts on our platform.

Write a program in Python that:
- Reads in the data in the file given, Sets up the appropriate classes/attributes/methods, Assigns definitions to each category, Prints out the report for all instances in the input file
Setting up the data:
Month name, Number of days in the month, Market name, Category name, Category definition, Store name, Store type, brand name, sales
The output should have 10 lines or sets of lines. The output will look like this:
For the month of April, Charmin Bath Tissue within Jewel Food stores had sales of $ 68 in the Chicago market for a market share of 52
For the month of April, Charmin Bath Tissue within Jewel Food stores had sales of $ 62 in the Chicago market for a market share of 47
File contents are in .csv file (excel) and were copied and pasted below:
April 30 Chicago Bath Tissue Jewel Food Charmin 68
June 30 Chicago Bath Tissue Jewel Food Charmin 74
April 30 Chicago Bath Tissue CVS Drug Charmin 96
June 30 Chicago Bath Tissue CVS Drug Charmin 33
April 30 Chicago Bath Tissue Jewel Food Scott 62
June 30 Chicago Bath Tissue Jewel Food Scott 87
April 30 Chicago Bath Tissue CVS Drug Scott 98
June 30 Chicago Bath Tissue CVS Drug Scott 39
April 30 Chicago Bath Tissue Marianos Food Charmin 85
June 30 Chicago Bath Tissue Marianos Food Charmin 20

Sagot :

Answer:

Explanation:

The following code is written in Python. It is a function that takes in the location of the csv file. Reads it line by line and ouputs the desired statement as seen in the example output provided in the question. The data does not provide the market share value to add to the statement so it was left blank.

from csv import reader

def printCSV(csv_file):

   with open(csv_file, 'r') as read_obj:

       csv_reader = reader(read_obj)

       for row in csv_reader:

           print(

               "For the month of " + row[0] + ", " + row[7] + " " + row[3] + " " + row[4] + " within " + row[5] + " " +

               row[6] + " stores had sales of $ " + row[8] + " in the " + row[2] + " market for a market share of ")

View image sandlee09