Handling an arbitrary number of salespeople

Once you know how to compute the commission for an arbitrary number of appliances and one salesperson,  the generalization to handling an arbitrary number of salesperson is not so hard.  In this blog we sketch a solution and we provide a complete program.  The program can be adapted and expanded in a number of ways.

The data about the salespeople would also be stoed in a file. Hence, there are two text files, sales_data_app.txt and sales_data_people.txt.  A next natural step is to compute and print  the commission of each salesperson. To solve this problem, we do the following:

  • We create a new class called Salesperson.
  • Every  Salesperson will have attributes.  A natural one the name, but others can be added (e.g., store location, title, etc).  In our solution we add the total commission earned, along with information on what the salesperson sold.  This information comes from file data_people.txt.
  • Every Salesperson will  have methods.  Examples are a method to calculate and return his or her total commission and a method to print out the ommission.

The Salesperson class may look like:

## define the salesperson class
class Salesperson:
    def __init__(self, name, quantity_list, appliance_list):
        ## put your code here     

    def get_total_commission(self):
        ## put your code here 

    def get_total_quantity(self):
        ## put your code here 

    def print_commission(self):
        ## put your code here

Try to design and implement your own problem using the classes Appliance and Salesperson. The following file contains one solution you can build on.
Download the program and data file