View the step-by-step solution to:

Use a list of lists to solve the following problem. A company has four salespeople (1 to 4) who sell five different products (1 to 5).


Use a list of lists to solve the following problem. A company has four salespeople (1 to 4) who sell five different products (1 to 5). Once a day,
each salesperson passes in a slip for each different type of product sold. Each slip contains:

a) The salesperson number.
b) The product number.
c) The number of that product sold that day.

Thus, each salesperson passes in between 0 and 5 sales slips per day. Assume that the information from all of the slips for last week is available.
Write a program that will read all this information for last month’s sales and summarize the total sales by salesperson by product.
All totals should be stored in list sales. After processing all the information for last week, display the results in tabular format, with each of
the columns representing a particular salesperson and each of the rows representing a particular product. Cross-total each row to get the total sales
of each product for last

week; cross-total each column to get the total sales by salesperson for last week. Your tabular printout should include these cross-totals to the right
of the totaled rows and at the bottom of the totaled columns.

Example use of list of lists:
>>> saledata=[[1,2,5],[1,4,10],[2,2,2],[2,3,10]]
>>> saledata[1][2]
10

The above represents 4 slips’ data.
The first item in a sublist is sales person id
The second item in a sublist is the product id
The third item in a sublist is the number of items sold

The number 10 above represents the number of items sold by sales ID 1 for product ID 4.

Note that the elements of a sublist can be accessed by using [][] with proper index values. All of the list commands are also applicable for sublists too.

Recently Asked Questions

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question