Question: The sales program found below is currently missing three desired pieces of functionality---it doesn't store record sales, nor is it able to print the top

The sales program found below is currently missing three desired pieces of functionality---it doesn't store record sales, nor is it able to print the top most expensive sales.

Provided for you is the RecordSale class which contains the album title and sale price for a particular record, and the SalesHistory class which is responsible for maintaining the list of past sales. Your task is to implement this missing functionality by defining two additional methods in the SalesHistory class: a) add_sale, and b) print_top_sales.

a) Defining the add_sale method

This method is to take an album title and its sale price as arguments, instantiate a new RecordSale object, and then append it to the sales instance variable (which is a list).

b) Defining the print_top_sales method

This method is to take no arguments and print the album title and sale price of the top three most expensive sales in descending order of price (i.e. highest to lowest). Each line in the output should be numbered (see example run).

In order to sort the auction sale items you should call the sort list method (documented here). You will need to make use of the sort method's two named arguments when calling it: key and reverse:

The key named argument can be provided with the name of a function (no parentheses). That function will be called for each item, and sorting will be based on the values returned by the function.

The reverse named argument can be provided with a boolean which determines whether the sort order should be reversed or not.

Hint: A function which returns the price of a record sale object has already been defined for you, and can be used as the key named argument for sort.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!