Question

In: Computer Science

Starting out with python Lists and Tuples - US Population Data In this assignment, you will...

Starting out with python

Lists and Tuples - US Population Data

In this assignment, you will be reading the contents of a file into a list.

This 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 populations for 1951, and so forth.

You will ask the user to input a specific year to check the population on.

Your program will then read the file's contents into a list. The program should display the following data:

1. The population for the year the user-specified.

2. The average annual change in population during the time period.

3. The year with the greatest increase in population during the time period.

4. The year with the smallest increase in population during the time period.

US Population:

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

Solutions

Expert Solution

path = "USPopulation.txt"

with open(path) as fp:

    population_list = list(map(int, fp.read().split()))

year = list(range(1950, 1991))


population_year = int(input("Input the Year: "))

if (population_year >= 1950 and population_year <= 1990):

    idx = year.index(population_year)

    print(f"The population for the year {population_year}.: ",population_list[idx])

else:

    print("INVALID")

change = []

for i in range(0,len(population_list)-1):

    change.append(population_list[i+1]-population_list[i])

total_elements_change = len(change)

print("The average annual change in population during the time period."+str(sum(change)/total_elements_change))


greatest_increase_pop = max(change)

greatest_increase_year = year[change.index(max(change))]

print("The year with the greatest increase in population during the time period."+str(greatest_increase_year))

smallest_increase_pop = min(change)

smallest_increase_year = year[change.index(min(change))]

print("The year with the smallest increase in population during the time period"+str(smallest_increase_year))

******************************************************************************************
PLEASE LIKE IT RAISE YOUR THUMBS UP
IF YOU ARE HAVING ANY DOUBT FEEL FREE TO ASK IN COMMENT SECTION
******************************************************************************************


Related Solutions

Using Python In this assignment we will try to add tuples, lists, if statements and strings...
Using Python In this assignment we will try to add tuples, lists, if statements and strings to our program. For example, you can ask for a user for a couple items, their name and age – and depending on their age, print out a predefined list. You could ask for some string input and decide to do something with the output. You could ask for three items, 1) age, 2) are you a male or female and 3) are your...
Python Programming- Practice Lists & Tuples B #This is a template for practicing mutability and conversion...
Python Programming- Practice Lists & Tuples B #This is a template for practicing mutability and conversion #Create and assign the following list of numbers to a list data type and variable name: 99.9,88.7,89,90,100 #convert the list to a tuple and assign the tuple a different variable name #Ask the user for a grade and convert it to a float type (no prompt) and assign it to a new variable name #append the user entered grade to the list #update the...
Describe how tuples can be useful with loops over lists and dictionaries, and give Python code...
Describe how tuples can be useful with loops over lists and dictionaries, and give Python code examples. Create your own code examples. Do not copy them from the textbook or any other source. Your descriptions and examples should include the following: the zip function, the enumerate function, and the items method.
"Python lists are power data structures. Describe some of the benefits of Python lists" Answer the...
"Python lists are power data structures. Describe some of the benefits of Python lists" Answer the question above in a few sentences.
In Python This assignment involves the use of text files, lists, and exception handling and is...
In Python This assignment involves the use of text files, lists, and exception handling and is a continuation of the baby file assignment. You should now have two files … one called boynames2014.txt and one called girlnames2014.txt - each containing the top 100 names for each gender from 2014. Write a program which allows the user to search your files for a boy or girl name and display where that name ranked in 2014. For example … >>>   Enter gender...
[Python programming] Functions, lists, dictionary, classes CANNOT BE USED!!! This assignment will give you more experience...
[Python programming] Functions, lists, dictionary, classes CANNOT BE USED!!! This assignment will give you more experience on the use of: 1. integers (int) 2. floats (float) 3. conditionals(if statements) 4. iteration(loops) The goal of this project is to make a fictitious comparison of the federal income. You will ask the user to input their taxable income. Use the income brackets given below to calculate the new and old income tax. For the sake of simplicity of the project we will...
Python Assignment You will be writing an inventory system that is backed by JSON data and...
Python Assignment You will be writing an inventory system that is backed by JSON data and will be working with a starter file that contains a JSON string. The code you write will need to follow the following guidelines. The what You’re at work one day and your boss asks you about that fancy programming language you’ve been learning, Python. She asks you if you can use it to read JSON data from a supplier and build an inventory. “Of...
Meta Language(ML) has two commonly used data structures(Lists and tuples). Distinguish between two of them and...
Meta Language(ML) has two commonly used data structures(Lists and tuples). Distinguish between two of them and rationalize your argument by the support of code snippet of each.        Lists Tuples How can we concatenate a string in Meta Language(ML)? Also write one coding example of string concatenation.                                                                                                                         What is meant by right-associative ? Elaborate it using an example.                                Write a condition in the given blank below using comparison operator to get the require output from this code.                                                                ...
You will be performing an analysis on heights in the US population, broken out by gender.
Make sure that all statistical analysis to be done in Excel and/or StatCrunch and answer all parts: You will be performing an analysis on heights in the US population, broken out by gender. You will need to know that US heights for males and females both follow an approximately normal distribution. The average height for women is 63.7 inches and a standard deviation of 2.7 inches. The average height for men is 69.1 inches and a standard deviation of 2.9...
Now let’s examine the effect of migration out of a population. The starting population of 1000...
Now let’s examine the effect of migration out of a population. The starting population of 1000 individuals is below: Genotype                                            # of individuals AA                                                      350 Aa                                                       400 aa                                                        250 What is the frequency of the A allele in the above population? 0.55 0.45 0.35 0.25 What is the frequency of the heterozygotes in the above population? 0.50 0.40 0.30 0.60 Now 50 individuals of the AA genotype and 50 individuals of the aa genotype leave the population. For this...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT