Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment Specifications Problem: Haggling Electronics Haggling Electronics is a new store that just opened where customers can haggle to get the best deal possible for

Assignment Specifications

Problem: Haggling Electronics

Haggling Electronics is a new store that just opened where customers can haggle to get the best deal possible for each item they buy.

The owner of the store, which just opened this year, heard you are taking a course on foundations in computing, and asks you to assist with some inquiries they have.

The store sells electronics and they have the list of all items they sell in a file called"transactions_Products.csv"where each line in the file consists of product ID, name of the product and price per unit in dollars separated by a comma. The first line of this file is the header of the three columns mentioned above respectively. Here is a sample from the file:

transactions_Products.csv

Product_ID,Product_Name,Price

P1,2-in-1 Laptop,1500

P2,Game Laptop,2000

P3,Titan Laptop,2100

Each time a customer comes to the store they can haggle and obtain a special discount.

The store keeps another file called"transactions_Sales.csv"to record transactions. Each line in this file consists of the transaction ID, a date for the transaction, a product ID, the number of items, and the obtained percentage of discount after haggling, all separated by a comma. The first line of this file is the header of these five columns. Here is a sample from the file:

transactions_Sales.csv

transaction_id,date,product_id,quantity,discount

1,1/2/2024,P10,1,0.03

2,1/2/2024,P1,2,0.13

3,1/2/2024,P15,2,0.13

The store has a policy of full refund if a purchased item is returned. In this case, all items under the transaction ID are returned, meaning the entire transaction is cancelled and refunded. To keep track of the returns, the store keeps a third file called"transactions_Returns.csv". Each line in this file consists of the transaction ID that was cancelled, and the date of the return, separated by a comma. The first line of this file is the header of these two columns. Here is a sample of the file:

transactions_Returns.csv

transaction_id,date

12,1/3/2024

23,1/3/2024

5 5,1/3/2024

The owner of Haggle Electronics is requesting your assistance. You are requested to write a Python program that can read these files, process them and yield the output to answer the following questions:

1-What is the product that led to the larger number of sales in units?

Print the top 3 with the product name (20 positions, right aligned) and the number of units sold (3 positions, right aligned), sorted by the number of units sold. There is one space between the two. Obviously, don't forget to account for the returns.

Here is a template for the output:

XXXXXXXXXXXXXXXXXXXX 999

2-What is the product that led to the larger number of sales in dollars?

Print the top 3 with product name (20 positions, right aligned) and amount in dollars (10 positions, 2 after the decimal point), sorted by the amount. For amounts, we want the comma as a separator for thousands like $123,345.78. Obviously, don't forget to account for the returns.

Here is a template for the output:

XXXXXXXXXXXXXXXXXXXX $999,999.00

3-What is the turnover for all sales?

Print a sorted table of all products each with the product ID (3 positions), the product name (20 positions), the total units sold (3 positions), the total amount obtained from the sale of that product (10 positions, 2 after the decimal point), average discount given for that product (5 positions, 2 after the decimal point and prefixed with 0 and followed by a % sign), and the total discounted amount for that product (10 positions, 2 after the decimal point),sorted by the total discounted amount. All dollar amounts should be prefixed by the $ sign. The comma should be used for thousand separators like in $ 98,765.43.

Do not forget to account for the returns.

The table should be framed with "|", "-" and "+". Here is a sample output:

+---+--------------------+---+-----------+------+-----------+

|P18|Universal Smart Remo| 33|$ 16,500.34|09.67%|$ 1,543.50|

+---+--------------------+---+-----------+------+-----------+

4-What are the number of transactions per weekday?

P rint the number of sales transactions per weekday. The weekday should be on 9 positions followed by the character ":", followed by the count on 3 positions.

Here is a template for the output:

XXXXXXXXX:999

5- What are the returned products?

Print a list of all the products and the number of times they were returned. For each product that was returned, print the product ID (3 positions), the product name (20 positions, left aligned), and the number of times it was returned (3 positions, right aligned), all separated by a space.

Here is a template for the output:

XXX XXXXXXXXXXXXXXXXXXXX 999

6-What is the performance of each product?

Create a text file named"transactions_units.txt"to record each line with the product ID and corresponding total units sold, separated by a comma.

When the alignment (left, right or other) is not specified in any of the questions above, use the default alignment.

Note that the example output given above may not exactly be related to the input examples provided here. Indeed, the output depends on 3 input files. The input and sample output provided here are just examples to indicate the format of all of the files.DO NOT hard code your output.The TAs will evaluate your assignment with different input files.

Stick to the required output format. Do not try to make it "nicer" or "more practical", or anything else. This is what the customer wants.

General Guidelines

In addition to making sure that your code runs properly, we will also check that you follow good programming practices. For example, divide the problem into smaller sub-problems, and write functions to solve those sub-problems so that each function has a single purpose; use the most appropriate data structures for your algorithm; use concise but descriptive variable names; define constants instead of hardcoding literal values throughout your code; include meaningful comments to document your code, as well as docstrings for all functions; and be sure to acknowledge any collaborators/references in a header comment at the top of your Python file.

Restrictions for this assignment:you cannot use break/continue, and you cannot import any modules exceptdatetime. Importing any other modules will result in deductions.

Assignment Deliverables

You are going to submit one Python program that performs the specified tasks.

Submission Instructions

Please follow these instructions to correctly submit your solution.

Name your solutionassignment1.py

Submit your program at the end of thispage

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_2

Step: 3

blur-text-image_3

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

International Marketing And Export Management

Authors: Gerald Albaum , Alexander Josiassen , Edwin Duerr

8th Edition

1292016922, 978-1292016924

More Books

Students also viewed these Algorithms questions

Question

When do you think a hiring decision will be made?

Answered: 1 week ago