Question: population.py Save the files named a USPopulation.txt from Module. This file contains the midyear population of the United States, in thousands, during the years 1
population.py
Save the files named a USPopulation.txt from Module. This file contains the midyear population of the United States, in thousands, during the years through
Write a program that reads the file's contents into a list. The program should display the following data:
The average annual change in population during the time period.
The year with the greatest increase in population during the time period.
The year with the smallest increase in population during the time period.
Hints
The program assumes that all population changes are positive. That is that each year the population was larger than the previous year.
Define main :
Open file for reading.
Read all the lines in the file into a list with readline method
Turn all read strings into numbers. use a for loop with range function and len of the list
Calculate the change in population size for each two years. another for loop with range function
If this is the first year, set trackers to its value.
Else this is not the first change in population size.
Calculate totalchange and averagechange
Display Average, greatest increase and smallest increase.
end main
Expected output:
The average annual change in population during the time period is
The year with the greatest increase in population was
The year with the smallest increase in population was
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
