A simple python program that shows the ranking of countries based on population growth.

A simple python program that shows the ranking of countries based on population growth.

Lab 6

This assignment is based on Textbook P8.17 and P8.18. The input file lab6Input.txt is fromhttps://www.cia.gov/library/publications/resources/the-world-factbook/rankorder/2002rank.html. It shows the ranking of countries based on population growth.

The program has a main function that calls the following 3 functions:

  • A function to read from the lab6input.txt file, which is a text version of the population growth page above. Each line of the file has 3 fields, separated by colon ( : ).Parse or separate each line of data and store the country name as a key and the growth rate as value in a dictionary. The ranking field is discarded. The input file should only be accessed by this function, so don’t open the file again after this function.
  • Since some of the country names may be difficult for the user to remember the exact spelling (Herzegovina? Vanuatu?), whenever the user enters a single letter at the search prompt, print all the country names that have the same starting letter. To do this, write a function that creates a dictionary with keys that are first letters of the countries, and the value of each key is a set of country names with the same starting letter. For example, the key ‘Z’ has a value which is the set (Zambia, Zimbabwe).
  • A function that loops to let the user enters in a full country name or a letter. If the user enters a name, print the corresponding growth rate. If the user enters a letter, print the set of country names that have a matching starting letter. If the name or the letter (both case insensitive) doesn’t exist, print an error message.

Sample output:

Enter a country name (or type quit to quit): v

VANUATU

VENEZUELA

VIETNAM

VIRGIN ISLANDS

Enter a country name (or type quit to quit): Venezuela

The growth rate is 1.28

Enter a country name (or type quit to quit): k

KAZAKHSTAN

KENYA

KIRIBATI

KOREA, NORTH

KOREA, SOUTH

KUWAIT

KYRGYZSTAN

Enter a country name (or type quit to quit): kazakhstan

The growth rate is 1.09

Enter a country name (or type quit to quit): ken

No such country name.

Enter a country name (or type quit to quit): kenya

The growth rate is 1.81

Enter a country name (or type quit to quit): q

QATAR

Enter a country name (or type quit to quit): quit

"You need a similar assignment done from scratch? Our qualified writers will help you with a guaranteed AI-free & plagiarism-free A+ quality paper, Confidentiality, Timely delivery & Livechat/phone Support.


Discount Code: CIPD30



Click ORDER NOW..

order custom paper