Each line in the file contains the name of a country the


Objectives:

  • specifically work with files, strings, lists, counters, and accumulators

Instructions:

write a program that reads data from a file and shows a report to the user in python.

Program Specification

Here is a link to a data file:

WorldData2012.txt

that contains population and land area data for hundreds of countries (and other geo-political units) adapted from this web site (Links to an external site.).  Each line in the file contains the name of a country, the population, and the land area, in that order.  Your job is to write a program that analyzes this data in various ways and shows a report to the user.  Here is what the program output should include:

  • the total number of countries in the list
  • the total world population
  • the name and population of the country that has the highest population
  • the name and population of the country that has the lowest population
  • the name and land area of the country that has the greatest land area
  • the name and land area of the country that has the smallest land area
  • the name and population density of the country that has the highest population density
  • the name and population density of the country that has the lowest population density
  • average population density (the average of the population densities of all the countries, not the population density of the planet as a whole)
  • a list of "densely populated countries" (those with a population density that is more than two times the average)
  • a list of "verysparsely populated countries" (those with a population density that is less than 1% of the average)

Note: land area is given is square kilometers (sq. km.), and "population density" is defined as "population per square kilometer."

Development Tips:

  1. Plan your program carefully on paper before you start writing code.  You may find the sample program illustrating the 'split' method to be a useful reference.
  2. How can you convince yourself that your program is producing correct results with such a large data file?  Consider creating a shorter file with the same format for initial testing purposes so that you can verify calculated results by hand.
  3. Here's one way to accomplish the last two tasks: 
  • The first time you read through the file, include an accumulator that allows you to determine the average of the population densities of all the countries.  Just calculate the population density for each country as you go, and then use the normal "find the average" pattern to determine the average value.
  • Read through the file a second time and use "sifting" operations to fill in the two lists.

Solution Preview :

Prepared by a verified Expert
Business Economics: Each line in the file contains the name of a country the
Reference No:- TGS02222694

Now Priced at $30 (50% Discount)

Recommended (92%)

Rated (4.4/5)