Question

The attached file US Population.txt contains the US population in thousands, during the years 1950 through 1990. The first li
151868 153982 156393 158956 161884 165069 168088 171187 174149 177135 179979 182992 185771 188483 191141 193526 195576 197457
0 0
Add a comment Improve this question Transcribed image text
Answer #1

PROGRAM :

try:

fp = open("Population.txt", "r")

avg = 0

prev_pop = int(fp.readline())

greatest_chg_yr = 1951

greatest_chg = 0

smallest_chg_yr = 1990

smallest_chg = prev_pop

c = 0

for line in fp.readlines():

curr_pop = int(line)

change = curr_pop - prev_pop

if(change>greatest_chg):

greatest_chg = change

greatest_chg_yr = c+1951

if(change<smallest_chg):

smallest_chg = change

smallest_chg_yr = c + 1951

prev_pop = curr_pop

avg += change

c += 1

fp.close()

avg /= c

print("Average annual change during the time period: "+str(avg))

print("The year with the greatest increase in population during the time period (highest growth rate): "+str(greatest_chg_yr))

print("The year with the smallest increase in population during the time period (smallest growth rate): "+str(smallest_chg_yr))

except FileNotFoundError:

print("Unable to open file Population.txt")

Population.txt:

151868 153982 156393 158956 161884 165069 168088 171187 174149 177135 179979 182992 185771 188483 191141 193526 195576 197457 199399 201385 203984 206827 209284 211357 213342 215465 217563 219760 222095 224567 227225 229466 231664 233792 235825 237924 240133 242289 244499 246819 249623

OUTPUT :

Average annual change during the time period: 2443.875 The year with the greatest increase in population during the time peri

Add a comment
Know the answer?
Add Answer to:
The attached file US Population.txt contains the US population in thousands, during the years 1950 through...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C# Visual Studio Problem You are given a file named USPopulation.txt. The file contains the midyear...

    C# Visual Studio Problem You are given a file named USPopulation.txt. The file contains the midyear population of the United States, in thousands, during the years 1950 through 1990. The first line in the file contains the population for 1950, the second line contains the population for 1951, and so forth. Create an application that reads the file’s contents into an array or a List. The application should display the following data (statistics) in read-only textboxes. The average population during...

  • In Python Please use the same USPopulation.txt file from Project 8 as input data. For this project, read the data into a list of lists (a 2-dimensional list, 4 decades, each decade with 10 years). Com...

    In Python Please use the same USPopulation.txt file from Project 8 as input data. For this project, read the data into a list of lists (a 2-dimensional list, 4 decades, each decade with 10 years). Compute the annual change in the population, and the year with the maximum and minimum population change. Using Anaconda, plot a graph for each decade's population change. The attached file USPopulation.txt contains the US population in thousands, during the years 1950 through 1990. The first...

  • the language is in Python please help Instructions from your teacher. Instructions The US Population.txt file...

    the language is in Python please help Instructions from your teacher. Instructions The US Population.txt file contains the midyear population of United States, in thousands, during the years 1950 through 1990. The first line in the file contains the population for 1950, the second line contains the population for 1951, and so forth. Create an application that reads the file's contents into a list. The application should do the following: • (15 points) Read the file into an list of...

  • Mike is a consultant for the Department of Labor. One day he is analyzing the midyear...

    Mike is a consultant for the Department of Labor. One day he is analyzing the midyear population of the United States, in thousands, during the years 1950 through 1990. He write Population Class in java including a main method as the testing client. His next task is to complete the entire class by adding: 1. A private field that can store a yearly population data as an integer array. 2. A constructor that can instantiate a Population object by using...

  • C++ ONLY The question is - The US Census Bureau gathers population information and aggregates it...

    C++ ONLY The question is - The US Census Bureau gathers population information and aggregates it at the city, county and state level. A research project on population distribution in the Southeast US has acquired a data file from the Census Bureau that contains the populations of each county in Mississippi (MS) and Florida (FL). For this research project write a program that calculates the average county population for these two states. Each line in the Census Bureau data file...

  • 4. Making graphs (spreadsheet): Use the snapshots.pdf file, together with its hyperlinks to the underlying spreadsheet...

    4. Making graphs (spreadsheet): Use the snapshots.pdf file, together with its hyperlinks to the underlying spreadsheet data. Use a spreadsheet program of your choice to complete the following. (a) Make a plot of per capita GDP (in dollars) for the years 1950 to 2014 for a country of your choice. Label the x-axis "year" and the y-axis "per capita GDP." Chapter 1 Introduction to Macroeconomics (b) Make a plot of per capita GDP relative to the United States (U.S. =...

  • Finish FormatJavaProgram.java that prompts the user for a file name and assumes that the file contains...

    Finish FormatJavaProgram.java that prompts the user for a file name and assumes that the file contains a Java program. Your program should read the file (e.g., InputFile.java) and output its contents properly indented to ProgramName_Formatted.java (e.g., InputFile_Formatted.java). (Note: It will be up to the user to change the name appropriately for compilation later.) When you see a left-brace character ({) in the file, increase your indentation level by NUM_SPACES spaces. When you see a right-brace character (}), decrease your indentation...

  • 1. Expense Pie Chart Create a text file that contains your expenses for last month in...

    1. Expense Pie Chart Create a text file that contains your expenses for last month in the following categories: -Rent -Gas -Food -Clothing -Car Payment -Misc Write a Python program that reads the data from the file and uses matplotlib to plot a pie chart showing you how you spend your money. 2. 1994 weekly gas graph The text file named 1994_Weekly_Gas_Averages.txt contains the average gas price for each week in the year 1994. (There are 52 lines in the...

  • Problem: You will write a program a C++ to compute some statistics based on monthly average...

    Problem: You will write a program a C++ to compute some statistics based on monthly average temperatures for a given month in each of the years 1901 to 2016. The data for the average August temperatures in the US has been downloaded from the Climate Change Knowledge Portal, and placed in a file named “tempAugData.txt”, available on the class website. The file contains a sequence of 116 values. The temperatures are in order, so that the first one is for...

  • Write a program that will accept from the user a text file containing hurricane data along...

    Write a program that will accept from the user a text file containing hurricane data along with an output filename. The data consists of the year, the number of storms, the number of hurricanes, and the damage in millions of US Dollars. The first line contains the word “Years” followed by the first year listed and the last year listed separated by tabs. The following lines contain the data separated by tabs. A sample text file is available in this...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT