Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In the cell below is a list of tuples, where each tuple is of the form (year, midyear-population) or (int, int). The data contained in

In the cell below is a list of tuples, where each tuple is of the form (year, midyear-population) or (int, int). The data contained in the list is based on estimates made by StatsCan of the Canadian population in the middle the given year and compiled together in one place by the Newfoundland and Labrador Statistics Agency. (The specific data provided in this assignment was obtained from https://bit.ly/293ECTS).

If you use shift-enter in the cell below, its definitions will become part of this notebook's variable definitions and will be afterwards accessible in any other code cell.

# population data MIDYEAR_POPULATION = [(1971, 21962032), (1972, 22218463), (1973, 22491777), (1974, 22807969), (1975, 23143275), (1976, 23449808), (1977, 23725843), (1978, 23963203), (1979, 24201544), (1980, 24515667), (1981, 24819915), (1982, 25116942), (1983, 25366451), (1984, 25607053), (1985, 25842116), (1986, 26100278), (1987, 26446601), (1988, 26791747), (1989, 27276781), (1990, 27691138), (1991, 28037420), (1992, 28371264), (1993, 28684764), (1994, 29000663), (1995, 29302311), (1996, 29610218), (1997, 29905948), (1998, 30155173), (1999, 30401286), (2000, 30685730), (2001, 31020596), (2002, 31358418), (2003, 31641630), (2004, 31938004), (2005, 32242364), (2006, 32570505), (2007, 32887928), (2008, 33245773), (2009, 33628571), (2010, 34005274), (2011, 34342780), (2012, 34750545), (2013, 35152370), (2014, 35535348), (2015, 35832513), (2016, 36264604), (2017, 36708083)]

Your task for part B of assignment #4 is to complete the functions greatest_increase, smallest_increase, and average_percentage_increase in the code cell below. Note that unlike in part A of this assignment where the data in the list could be accessed as a global variable in this part of the assignment the list must be passed as an argument to the three functions.

The code for main is already provided to you.

Please note that we will test your assignment with data other than that provided in the cell above. For example, assuming the data used is as follows (with test_list defined in the main function):

test_list = [(1900, 10000), (1901, 10100), (1902, 10211), (1903, 10287)]

then the following is an expected transcript from a completed solution:

Greatest increase: 1902 111 Smallest increase: 1903 76 Average percentage increase: 0.95%

Do not use any libraries for this assignment other than the standard library (i.e., no use of NumPy, SciPy, pandas etc. is permitted).

Hint: To iterate through a list starting from the second element, we can write:

for elem in some_list[1:]: # body of for-loop

def greatest_increase(pop_stats): """ function: greatest_increase Given a list of tuples of the form (year, population), the function finds the year for which is recorded the greatest increase in population from the previous year. Input: ------ * pop_stats: A list of tuples of the form (year, population). The tuples are sorted by year, and there are no gaps between years. Outputs: -------- * A pair of values consisting of the year with the greatest population increase, and the amount of that increase. """ return 0, 0

def smallest_increase(pop_stats): """ function: smallest_increase Given a list of tuples of the form (year, population), the function finds the year for which is recorded the smallest increase in population from the previous year. Input: ------ * pop_stats: A list of tuples of the form (year, population). The tuples are sorted by year, and there are no gaps between years. Outputs: -------- * A pair of values consisting of the year with the smallest population increase, and the amount of that increase. """ return 0, 0

def average_percentage_increase(pop_stats): """ function: average_percentage_increase Given a list of tuples of the form (year, population), the function computes the percentage change in population from year to year, and returns the average percentage change (i.e., a number from 0 to 100). Input: ------ * pop_stats: A list of tuples of the form (year, population). The tuples are sorted by year, and there are no gaps between years. Output: -------- * A single value that is the average of percentage changes from year to year (i.e., a value from 0.0 to 100.0). """ return 0

def main(): year, increase = greatest_increase(MIDYEAR_POPULATION) print("Greatest increase: ", year, increase) year, increase = smallest_increase(MIDYEAR_POPULATION) print("Smallest increase: ", year, increase) average = average_percentage_increase(MIDYEAR_POPULATION) print("Average percentage increase: ", format(average, ".2f"), "%", sep="") main()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Visual Basic Net Database Programming

Authors: Rod Stephens

1st Edition

0789726815, 978-0789726810

More Books

Students also viewed these Databases questions

Question

Of the four options available to Angi, which is the most ethical?

Answered: 1 week ago