As always, run update21, to create the cs21/labs/08 directory. Then cd into your cs21/labs/08 directory and create the program for lab 8 in this directory
This week's lab involves climate data for different countries. The file /usr/local/doc/climatedata.csv contains data from the CAIT Climate Data Explorer. Here are the first few lines from climatedata.csv:
Afghanistan|30682500|19731.34|0|15.21|44.42 Albania|2896652|12542.47|2319|11.84|7.95 Algeria|38186135|176324.90|47580|91.71|186.84 Angola|23448202|96261.43|15356|160.32|270.19 Antigua & Barbuda|89985|1155.65|0|0.40|1.11 Argentina|42538304|457639.09|80594|303.46|431.64
Each line contains data for a different country. The lines in the file are in alphabetical order based on the name of the country. Here's a handy chart for the position and meaning of each piece of data:
Your job this week is to write a program (ghg.py) that reads in the climate data and displays the following information:
Country: Brazil
Name: Brazil
Population: 204259377
GDP USD: 2409739
Energy Use: 293683
GHG 1990: 1447.7
GHG 2013: 1317.2
Change/year: -5.7
To get the information required above, you will (obviously) have to search
through the climate data. For many of the searches, since the data is only sorted
alphabetically by country, you will have to use a linear search. For the last one
(search for data about a specific country) you can/should use a binary search.
Here are the specifications for this program and a few helpful "tips". Make sure your program meets all of these specifications.
[[data for country 1], [data for country 2], [data for country 3], ...]Here's what the inner lists for each country should contain:
[Name,Pop,GDP,EnergyUse,GHG1990,GHG2013,AvgChangePerYear]
>>> print(LOL) [['Afghanistan',30682500,19731.34], ['Albania',2896652,12542.47], ['Algeria',38186135,176324.9]] >>> cdata = LOL[0] >>> print(cdata) ['Afghanistan', 30682500, 19731.34] >>> print(cdata[0]) Afghanistan >>> >>> print(LOL[0]) ['Afghanistan', 30682500, 19731.34] >>> print(LOL[0][0]) Afghanistan
['Germany', 82132753, 3577227.56, 317658, 1103.55, 856.69, -10.733043478260866]
>>> S = "a|b|c|d" >>> data = S.split("|") >>> print(data) ['a', 'b', 'c', 'd']
Country: genovia genovia not found... Country: germany Name: Germany Population: 82132753 GDP USD: 3577227 Energy Use: 317658 GHG 1990: 1103.5 GHG 2013: 856.7 Change/year: -10.7
Once you are confident that your program works, fill out the questionnaire in README-08.txt.
Then run handin21 a final time to make sure we have access to the most recent versions of the files required for this lab.