Question
Part 1 (40 points) Read inworld_population_2017.tsvand create dictionary. Start out by filling in the makePopDictionary function definition so that it reads the input file world_population_2017.tsv.
Part 1 (40 points)
Read inworld_population_2017.tsvand create dictionary.
Start out by filling in the makePopDictionary function definition so that it reads the input file world_population_2017.tsv. You are already familiar with reading comma separated files from the last assignment. In the tsv file the row number, country name, and population are separated by the tab character "\t", instead of a comma.
You are interested in extracting the country name and population as variables. You will need to convert population from a string to an integer.The string method replace() can be used to remove the commas from the numbers by replacing them with the empty string.
Add a temporary print statement to check that you correctly extracted the data from the file; e.g.print(country,population).
Test your code by calling makePopDictionary from main and running your program.
You should see the following at the end when it is done. The values will be printed in the same order as in the file, but separated by a space instead of a tab.
China 1379302771
India 1281935911
United States 326625791
Indonesia 260580739
Brazil 207353391
When you are satisfied it works, you can now populate the dictionary and return it from the function.
Part 2 (40 pts):
Read the drinkingWater.csv file and compute access
Start by removing the print statement in makePopDictionary and adding a call to readDWdata in main(). Your test program will now be printing out
In the readDWdata function, write the code for reading in the drinkingWater.csv file and extracting the country name and the percentages for 1990 and 2010. If a country does not have percentages for both year then you will skip it. Next compute how access has changed by subtracting the percentage in 1990 from the percentage in 2010. Print out the name of the country, the two percentages, and the difference.
The first five lines of your output should look like:
World 7688 12
Developing countries 7086 16
Africa 5666 10
North Africa 8792 5
Algeria 9483 -11
Part 3 (20 pts)
Now we are only interested in printing the values only for countries that match keys in the population dictionary and have populations over 500,000.You do not have to worry about country names that don't match exactly, such as United States of America vs United States. Your program can mistakenly assume that these are different countries.
Add a first line that describes the column contents (see below). You do not have to write the output to a file for this assignment, it will be sufficient to print it to the screen.
Now, the first five lines of your output should look like:
Country19902010Change
Algeria 9483 -11
Egypt 9399 6
Morocco 7383 10
Angola 4251 9
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started