Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

PYTHON PYTHON PYTHON! Exercise 1 sales.txt is a file provided in the homework section for this week. It is tab delimited and has order number,

PYTHON PYTHON PYTHON!

Exercise 1

sales.txt is a file provided in the homework section for this week. It is tab delimited and has order number, the number of products purchased on that order, and the profit earned on that order.

Write a script that reads the file and prints out:

  • The order number that had the greatest number of items ordered
  • The order number that earned the most profit

You must calculate the answers in your script (e.g. you can't just go through the file yourself, find the answer, and write a script that prints those numbers out). Your output should look like this (note that these are made up values to show format and not the correct values):

Order with most products: 188939527 Order with most profit:1938882

Exercise 2

Using the sales data from above, write a script that has two dictionaries, one for number of items ordered and one for profit earned. Use the order number for the key in each dictionary. Using pickle, dump the dictionaries into a single file. You MUST dump the dictionary for number of products ordered first and the dictionary for profit second. Submit your python script AND your output file.

YOU MUST HAVE ONLY ONE OUTPUT FILE THAT STORES BOTH DICTIONARIES.

Exercise 3

Write a script that will load the two dictionaries from an Exercise 2 output file. Then, using the dictionaries, print the average number of products ordered per order and the average profit per order. Your script will be tested on other people's Exercise 2 output and your Exercise 2 output will be tested with other people's scripts. Your output should look like this (note that these are made up values to show format and not the correct values):

Average products per order: 3.1 Average profit per order: 1.2

sales.txt file:

https://drive.google.com/file/d/19_osLNroQeZVWxXCSq_aoXGE5Iu0QfRU/view?usp=sharing

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions