Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Look at the file widget_sales.txt (under Resources). This is the number of sales

ID: 3792400 • Letter: L

Question

Look at the file widget_sales.txt (under Resources). This is the number of sales over 12 months for a small company that has 6 employees. You will note that each month is separated from the next month by a tab character (represented by   ) .  For example, employee #1 sold 2386 widgets in January, 2176 widgets in Febuary, and 2315 widgets in December.

In Python, write a function called total_sales_emp() that accepts one argument that represents an employee number.  This function should return the total sales of that employee over the year. For example, total_sales_emp(1) would return the total number of widget sales by employee #1 which is 26,563 widgets. Prompt the user for an employee number (tell them it should be between 1 and 6), and then output the number of sales for that employee. Here are some sample runs. Note: The total values shown here are correct – you can use them to make sure your program is doing the calculations properly.

Your output statement strings should match the ones demonstrated below:

3.Using the same file as above, write a function called that simply returns the total widget sales of all employees over the year. (When you test your code, the result should be 157105 widgets). You should use a nested loop to do this calculation.

Employee number (1-6) 1 Employee 1 sold 26563 widgets last year. RESTART: C: /Dropbox /241 Employee number (1-6) 6 Employee 6 sold 26627 widgets last year

Explanation / Answer

Import urllib2

Rs=urllib2.urlopen("test.txt");

Totalgadgets={}

For line in rs.read().Split(" "):

_,_,title,gadgets=line.split(' ');

If not totalgadgets.has_key(title):

Total assets[title]=[]

Totalgadgets[title].Append(float(gadgets)):

For title,gadgets in totalgadgets

Print title

Print 'employ number':title

Print'eolly sold gadgets',sum(gadgets)

Print

Totalemployees={}

For employees, totalgadgetsin totalemployes

Print employee

Print'total employee gadgets'sum(totalgadgets)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote