Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask PL-SQL Expert

This task involves developing some functions that extract data from an SQL database. The scenario is that a company which owns an online vehicle search website wants to generate some statistics about their car dataset so that they can have a better idea about its distribution. You are asked to write four Python functions to generate the required statistics.

1.  Write a Python function named top_N_models(make, N) that generates the number of occurrences of each model of a specified car make and prints the top N most frequent models for that car make together with their corresponding number of occurrences, one model per line.   This function has two parameters.    The first parameter is a string specifying a car make. The second parameter is an integer indicating the number of top models to be printed.   For example, for function call top_N_models('BMW', 2), if the top two most frequent models of  BMW are  M3 with frequency 30 and M5 with frequency 25, your function is expected to produce the following result:      

>>> top_N_models('BMW', 2) 

M3 30

M5 25

Note that if there are no details for the specified make of car in the database an appropriate error message must be printed.  (Hint: A non-existent row or field will be represented by the special Python value  None.)  See the unit tests in question file  top_N_models_Q.py for further detail.

2.  Write a Python function named top_N_expensive(N)  that prints the make, model, and price of the top  N most expensive cars, one car per line.   The output should be ordered  in  descending order  by price first, then  in ascending order by  car make, and finally  in  descending order by  car model.   Moreover, the output should not contain duplicates, i.e., any two lines in the output can't be exactly the same.   This function has only one parameter, N, which indicates the number of makes to be printed.

For example, if the top five most expensive cars are MERCEDES-BENZ CLK320 with price $99,990, BMW X5 with price $89,400, BMW M5 with price $89,400, LEXUS LS430 with price $85,000, and BMW Z4 with price $85,000, the output of your function should be as follows.

  >>> top_N_expensive(5) 

MERCEDES-BENZ CLK320 $99990

BMW X5 $89400

BMW M5 $89400

BMW Z4 $85000

LEXUS LS430 $85000

3.  Write a Python function named min_max(make)that prints the  range of prices of  the cars with the specified make.  For example, if the maximum price and minimum price of all Toyotas in the database are  $32,000 and  $3,000, respectively, your function should produce the following result.

>>> min_max('TOYOTA') 

TOYOTA ($3000-$32000)

 Notice that the string printed should be formatted so that it is easy to read.  Also, if there are no details for the specified make of car in the database an appropriate error message must be printed.  

(Hint: A non-existent row or field will be represented by the special Python value  None.)   See the unit tests in question file  min_max_Q.py for further detail.

Development hints

Before you can begin this task you must ensure that you have access to MySQL software and the MySQL Workbench so that you can create the database.  You must also have access to an appropriate MySQL-Python module so that you can call MySQL functions from Python code.  This will be either MySQLdb (for Windows users) or the MySQL Connector (for Mac users). 

You need to write four Python programs for this task to retrieve data from the database.  The four programs are independent from each other. You don't have  to start from the first program.  You can choose any one to start with.

Deliverables

The deliverables for this task are the four completed Python programs,

  1. min_max.py,
  2. top_N_expensive.py,
  3. top_N_makes.py and
  4. top_N_models.py.

Note that the "_Q" question suffixes have been removed from the file names.  These programs must pass all of the unit tests in the supplied program templates  without modification. You do not need to submit any SQL database scripts or dumps.  We will use our own SQL database to test your software.

PL-SQL, Programming

  • Category:- PL-SQL
  • Reference No.:- M9522663

Have any Question?


Related Questions in PL-SQL

Assignment - queries functions and triggersaimthe aims of

Assignment - Queries, Functions and Triggers Aim The aims of this assignment are to: formulate SQL queries; populate an RDBMS with a real dataset, and analyse the data; design test data for testing SQL queries; create SQ ...

Complete the following tasksin microsoft access create the

Complete the following tasks: In Microsoft Access, create the database and tables that you identified in W3 Assignment 2. In Microsoft Word, write the SQL statements to create the database and tables. Write SQL statement ...

Continuing the project you have worked on in weeks 1-4 in

Continuing the project you have worked on in Weeks 1-4, in this final week, complete the following tasks: Refine your database and SQL statements by incorporating your instructor's feedback. Verify that the database comp ...

Purpose of the assessment with ulo mapping the purpose of

Purpose of the assessment (with ULO Mapping) The purpose of this assignment is to develop skills in managing data in databases and to gain understanding of data model development and implementation using a commercially a ...

For this assignment you will be provided a database backup

For this assignment, you will be provided a database backup for a database called FinanceDB. You will have to restore this backup to your own version of SQL Server. All of the questions in this assignment relate to the F ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As