Earn Higher Grades With Instant Assignment Help.Ask Question!

Python Programming
(5/5)

Introduction to Software Development has 4 courseworks. Each coursework contributes equally to the overall coursework mark.

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

Preliminaries - Important Please Read Carefully

  1. Read carefully the plagiarism statement at: http://www.bbk.ac.uk/registry/policies/documents/assessment-offences-policy.  pdf

Once you have read it, add to the top of Term2cw1.py as a multi-line comment, the following:

I have read and understood the sections of plagiarism in the College Policy  on assessment offences and confirm that the work is my own,

with the work of others clearly acknowledged.

I give my permission to submit my work to the plagiarism testing database that the College is using and test it using plagiarism detection software, search engines or meta-searching software.

You will get 0 marks if this is not included in your submission

  1. Do not use Github or any publicly accessible site to store your This will be regarded as a plagiarism offence.

  2. Do not be tempted to use contractor websites to find somebody to do the coursework for

  3. Download from Moodle py, testscript.py, PGS.dat, EGL.dat, BatchQueries.dat, BatchQueriesout.dat. Place them all in the same di- rectory of your choosing. I have provided you with a

file Term2cw1.py which has the function

definitions you need to implement, add any further functions you wish to write into this

file. testscript.py will test your script for correctness. Please note that passing these tests only demonstrates that you have understood the ex- amples provided in this document. To check for correctness, I shall run

 own script on your submitted work. I shall release this script as part of the coursework feedback. Run testscript.py. You should get the following output:

 

Step 1 Success! - outcomes

Step 1 Success! - property names Step 1 Success! - ranges

Step 2 Success! - Outcome

Step 2 Success! - Bad Properties Step 3 Success!

 

If you have been successful in writing the code, running this script again will display the following

 

Step 1 Failed - outcomes

Step 1 Failed - property names Step 1 Failed - ranges

Step 2 Failed - Outcome

Step 2 Failed - Bad Properties Step 3 Failed

 

Note I have not provided a test for Step 4.

 

The Coursework

Introduction to Software Development has 4 courseworks. Each coursework contributes equally to the overall coursework mark.

By doing this coursework you will get experience in reading from and writing to files and you will get experience in automatically processing data.

 

The Exercise - Overview

There exist several gem institutes that grade diamonds. They all have different systems for classification. For example, EGL1 considers

 

Measurement

Good Quality

Table width

Between 53.0 to 58.0 inclusive

Crown Height

Between 13.0 to 17.0 inclusive

Crown Angle

Between 33.0 to 36.0 inclusive

Pavilion Depth

Between 42.0 to 44.0 inclusive

Pavilion Angle

Between 40.0 to 41.2 inclusive

Total Depth

Between 58.5 to 62.5 inclusive

In reality EGL and PGS use more properties than the ones shown

If the diamond is inside of these ranges then it is classed as Ideal cut otherwise it is classed as Not Ideal cut.

Another gem institute, PGS, uses fewer properties and has different intervals:

Measurement

Good Quality

Table width

Between 53.0 to 57.0 inclusive

Crown Height

Between 14.0 to 16.5 inclusive

Crown Angle

Between 33.5 to 35.5 inclusive

Pavilion Depth

Between 42.5 to 44.0 inclusive

Pavilion Angle

Between 40.5 to 41.0 inclusive

If the diamond is inside of these ranges then it is classed as Excellent Ideal cut

otherwise it is classed as Not Excellent Ideal cut.

You are to write a batch processor for answering queries about diamonds using the data from gem institutes. You program will accept a filename that consists of queries, one query from one user on each line, such as: UID86903202,PGS,53.1,14.2,33.5,42.5,40.5 UID76963403,EGL,53.1,14.2,33.5,42.5,40.5,59.0 UID83240543,EGL,58.0,15.1,35.25,43.0,41.2,62.5 UID94470534,PGS,53.1,14.2,33.5,42.5,41.5 UID24642541,ABC,53.1,14.2,33.5,42.5,41.5 UID98730542,PGS,fifty,14.2,33.5,42.5,41.5 UID98037245,PGS,53.1,14.2,33.5,42.5

Your program will write file containing the answer for each query in the same order keeping the user ID. For example:

UID86903202, Excellent Ideal cut UID76963403, Ideal cut UID83240543, Ideal cut

UID94470534, Not Excellent Ideal cut, Pavilion Angle UID24642541, Data for this Institute not currently available UID98730542, Input values not valid

UID98037245, Number of input values do not match the number of properties

The data used to answer the queries are stored in files that you must be able to read. The following sections will guide you through the process and provide all the necessary detail. The questions are ordered such that you can incrementally build up to the complete solution.

 

The Questions

There are 4 parts. This coursework is marked out of 50. All questions must be answered using Python 3 programming language.

Always keep backup copies of all assignments. If your assignment gets lost, a backup copy will make things easier for you. Review both Coursework 1 and Coursework 2 using my sample solutions

  1. (10 marks)

Before we can answer a query we will need to be able to read in the relevant data.

Write a function called LoadData, this function has 1 argument called

sName.

The function returns a tuple containing 3 lists. This function reads in a data file containing all the information relevant to a query. For example, the content of EGL.dat is:

Table width,53.0,58.0 Crown Height,13.0,17.0 Crown Angle,33.0,36.0 Pavilion Depth,42.0,44.0 Pavilion Angle,40.0,41.2 Total Depth,58.5,62.5

Ideal cut

Not Ideal cut

 

 

The format of this file is as follows. First there is a block properties and their ranges, one on each line. Then there is a divider (--------------- ), the

there are two outputs, the first is the classification of a good diamond and the second is the classification of a bad diamond Below is the content of PGS.dat.

 

Table   width,53,57 Crown Height,14.0,16.5 Crown Angle,33.5,35.5

 
   


Pavilion Depth,42.5,44.0 Pavilion Angle,40.5,41.0

Excellent Ideal cut

Not Excellent Ideal cut

 

Your function accepts a string such as ’PGS’ and opens a file called ’PGS.dat’. It will be assumed that this and any other file are in the current working directory so you do not need to include a path.

Your function will return a tuple of 3 lists. The first list will be the list of possible answers (as strings), followed by a list of possible types (as strings) and finally a list of lists containing the range values which will always be floating point numbers. For the PGS.dat file, this would be:

 

([’Excellent Ideal cut’, ’Not Excellent Ideal cut’],

[’Table width’, ’Crown Height’, ’Crown Angle’, ’Pavilion Depth’, ’Pavilion Angle’], [[53.0, 57.0], [14.0, 16.5], [33.5, 35.5], [42.5, 44.0], [40.5, 41.0]])

 

You can assume that there are no errors in the file, and that the file exists,

i.e. do not include any exception handling in this function. Do not test to see if you can cast to float.

I shall test the correctness of your function by adding new data files that you have not been supplied with, so do not hard-code any of the data from the supplied data files.

  1. (10 marks) Read through my sample solution for Term 1 Coursework 2, you may reuse any code you see fit to answer the following

Write a function that has the following name and arguments:

GetFeedback(outcomes, propertyNames, ranges, inputProperties)

The arguments outcomes, propertyNames, ranges are the values re- turned from LoadData():

 

(outcomes, propertyNames, ranges) = LoadData("PGS")

The argument inputProperties is a list of the properties of a diamond to be classified.

This function returns a tuple containing 2 strings; the answer as string and a validation string :

(outcomes, propertyNames, ranges)  =  LoadData("PGS") print(GetFeedback(outcomes, propertyNames, ranges,[53.1,14.2,33.5,10.5,41.5]))

displays

(’Not Excellent Ideal cut’, [’Pavilion Depth’, ’Pavilion Angle’])

The first element of the returned list is outcome of the classification, the second element is a list of the names all the properties that failed.

  1. (10 marks)

Only continue to the remaining questions if you have success- fully written the above code. You will receive a mark of zero for parts 3 and 4 if the code you have so far written either does not work or has data hard-coded into it.

Write a function that has the following name and arguments:

ProcessQuery(gemInstitute, inputProperties)

gemInstitute is a string containing the name of the file to open. inputProperties

is defined in the same way as for the function GetFeedback. This function does a lot of the error checking as follows:

If the call to LoadData() fails for any reason then return

(’Data for this Institute not currently available’,’’)

 

If the length of the list inputProperties does not equal the number of property names then return

(’Number of input values do not match the number of properties’,’’)

 

If you are unable to cast all the elements in inputProperties to float then return

(’Input values not valid’,’’)

 

Finally if all the above tests are fine, then return a tuple with the first element

"Inputs are all valid"

The second element is the output from GetFeedback

 

For ProcessQuery("PGS",[50.1,14.2,33.5,42.5,41.5])

The returned value is

(’Inputs are all valid’, (’Not Excellent Ideal cut’, [’Table width’, ’Pavilion Angle’])

 

  1. (10 marks)

Write a function called:

ProcessBatch(filename)

 

This function appends .dat to the filename and opens this file to read. It also appends out.dat to the filename to produce a file to write its output to.

For example ProcessBatch(’batch’), opens a file called batch.dat and writes output to batchout.dat.

If the program fails in any way, catch the issue and print ”Could not process file” to the screen. You must close the files when the function ends.

A batch file consists of multiple queries, one on each line:

UID8693202,PGS,53.1,14.2,33.5,42.5,40.5 UID76963403,EGL,53.1,14.2,33.5,42.5,40.5,59.0 UID83240543,EGL,58.0,15.1,35.25,43.0,41.2,62.5 UID94470534,PGS,50.1,14.2,33.5,42.5,41.5 UID24642541,ABC,53.1,14.2,33.5,42.5,41.5 UID98730542,PGS,fifty,14.2,33.5,42.5,41.5 UID9803245,PGS,53.1,14.2,33.5,42.5

Each line has the following pieces of information: A user ID, a gem insti- tute (that corresponds to a file name used to store the relevant data), a list of a diamond’s properties. The information is comma separated.

Your function must write out a corresponding file that has the answer or feedback about the validity of the input, if the inputs are not correct. If the file holding the data does not exist the output for that particular user query must be:

 

’Data for this Institute not currently available’

 

For the above input file, the content of the corresponding output file is the following: (Note that there is no institute called ABC.)

UID86903202, Excellent Ideal cut UID76963403, Ideal cut UID83240543, Ideal cut

UID94470534, Not Excellent Ideal cut, Table width, Pavilion Angle UID24642541, Data for this Institute not currently available UID98730542, Input values not valid

UID98037245, Number of input values do not match the number of properties

 

  1. (10 marks)

For code quality and for correctly following the submission instructions below. Please ensure you have the following:

  • See function comments in Section 5.2

  • Appropriate variable, function and argument

Submitting the assignment:

  1. Do not forget the plagiarism declaration comment at the top of your You will get 0 marks if it is not there.

  2. Do not include a main() function in your

  3. Do not hardcode a directory into your

  4. Only include function Do not have any test or example code that will be evaluated if your file is run.

  5. Include a further comment directly after the plagiarism declaration that has your name, the name of the programme you are taking (e.g., MSc IT, etc.), and the submission

  6. Submit only your py do not zip your file. Do not rename this file.

  7. Submission is only through

  8. To submit your file, follow the Upload Submission for Term2 - Course- work1 link on the ISD Moodle

Attachments:
(5/5)

Related Questions

CSI 1420 Introduction to C Programming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two majorconstructs of the C programming language – Fu

The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Ask This Assignment To Be Done By Our ExpertsGet A+ Grade Solution Guaranteed

expert
joyComputer science
(4/5)
12 Answers Hire Me
expert
Robert DLaw
(4.8/5)
862 Answers Hire Me
expert
Dr Samuel BarberaStatistics
(5/5)
837 Answers Hire Me
expert
Tutor For YouEconomics
(5/5)
644 Answers Hire Me