diff_months: 14

You are required to write a Python 3 program that will read a CSV file.

Download Solution Now
Added on: 2023-04-25 04:41:49
Order Code: 489037
Question Task Id: 0

After reading the file, your program is required to complete the following statistical tasks:

1) Find the country name which has minimum and maximum population in a specific region which has positive net change in population.

2) Calculate the average and standard deviation of population for a specific region.

3) Calculate the density of population for each country in a specific region.

4) Calculate the correlation between population and land area for all the countries in a specific region.


1) You are not allowed to import any external or internal module in python. While use of many of these modules, e.g. csv or math is a perfectly sensible thing to do in production setting, it takes away much of the point of different aspects of the project, which is about getting practice opening text files, processing text file data, and use of basic Python structures, in this case lists and loops.

2) Ensure your program does NOT call the input() function at any time. Calling the input() function will cause your program to hang, waiting for input that automated testing system will not provide (in fact, what will happen is that if the marking program detects the call(s), it will not test your code at all which may result in zero grade).

3) Your program should also not call print() function at any time except for the case of graceful termination (if needed). If your program has encountered an error state and is exiting gracefully then your program needs to return zero as the value for the correlation otherwise empty list and print an appropriate message. At no point should you print the program's outputs instead of (or in addition to) returning them or provide a printout of the program's progress in calculating such outputs.XXXXXXXXXXXXXX,5235 154,765 123,5235 CITS1401 Computational Thinking with Python Project 1 Semester 1 2023 Page 3 of 6

4) Do not assume that the input file names will end in .csv. File name suffixes such as .csv and .txt are not mandatory in systems other than Microsoft Windows. Do not enforce that within your program that the file must end with a .csv or any other extension (or try to add an extension onto the provided csv file argument), doing so can easily lead to loosing marks.

Input: Your program must define the function main with the following syntax: def main(csvfile, region): The input arguments for this function are:

• csvfile: The name of the CSV file (as string) containing the record of the population of all countries in the world.

Below is the first row of the sample file:

• region: The dataset has multiple regions and their population details. It will be a string parameter containing name of a region.

Output: Four outputs are expected in the order below.

i) A list containing the name of countries having maximum and minimum population in the input region where net change in population is positive. Your output should be stored in a list in the following order: [country with maximum population, country with minimum population] For example: [India, Srilanka]

ii) A list containing the average and standard deviation of population in the input region when distributed over the number of countries in the input region. Your output should be stored in a list in the following order: [average, standard deviation] For example: [ 300000, 15.6]

iii) A list of a list containing the name and density of each country for the input region in descending order. Your output should be stored in a list of lists in the following order: [ [country1,density1] , [country2,density2] , [countryN, densityN] ] For example: [ [china, 156], [India, 109], [Bangladesh, 73] ]

iv) A numeric value containing the correlation between the population and the land area for all the countries in the input region. The expected output is a single float value. All returned numeric outputs (both in lists and individual) must contain values rounded to four decimal places (if required to be rounded off).

Do not round the values during calculations. Instead round them only at the time when you save them into the final output variables. CITS1401 Computational Thinking with Python Project 1 Semester 1 2023 Page 4 of 6 Examples: Download countries.csv file from the folder of Project 1 on LMS or Moodle. An example of how you can call your program from the Python shell (and examine the results it returns) is provided below: >>> MaxMin, stdvAverage, density, corr = main('countries.csv', 'Africa') The output variables returned are: >>> MaxMin ['Western Sahara', 'Seychelles'] >>> stdvAverage [291620.6667, 239936.4497] >>> density [['Mayotte',727.5067],['Sao Tome & Principe',228.2906], ['Cabo Verde',137.9620], ['Saint Helena',15.5821], ['Seychelles',11.0008], ['Western Sahara', 2.2456]] >>> corr 0.6243

Assumptions: Your program can assume the following:

• Anything that is meant to be string (e.g. header) will be a string, and anything that is meant to be numeric will be numeric.

• The order of columns in each row will follow the order of the headings provided in the first row. However rows can be in random order except the first row which contains the headings.

• No data will be missing in the CSV file; however values can be zero and must be accounted for when calculating averages and standard deviations.

• The main function() will always be provided with valid input parameters.

• The necessary formulas are provided at the end of this document.

Important grading

instruction: Note that you have not been asked to write specific functions.

The task has been left to you. However, it is essential that your program defines the top-level function main(csvfile, region) (commonly referred to as “main()" in the project documents to save space when writing it. Note that when main() is written it still implies that it is defined with its two input arguments). The idea is that within main(), the program calls the other functions. (Of course, these functions may then call further functions.) Thisis important because when your code is tested on Moodle, the testing program will call your main() function. So if you fail to define main(), the testing program will not be able to test your code and your submission will be graded zero. Don't forget the submission guidelines provided at the start of this document.

  • Uploaded By : Katthy Wills
  • Posted on : April 25th, 2023
  • Downloads : 0
  • Views : 173

Download Solution Now

Can't find what you're looking for?

Whatsapp Tap to ChatGet instant assistance

Choose a Plan


80 USD
  • All in Gold, plus:
  • 30-minute live one-to-one session with an expert
    • Understanding Marking Rubric
    • Understanding task requirements
    • Structuring & Formatting
    • Referencing & Citing


30 50 USD
  • Get the Full Used Solution
    (Solution is already submitted and 100% plagiarised.
    Can only be used for reference purposes)
Save 33%


20 USD
  • Journals
  • Peer-Reviewed Articles
  • Books
  • Various other Data Sources – ProQuest, Informit, Scopus, Academic Search Complete, EBSCO, Exerpta Medica Database, and more