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.
"Python lists are power data structures. Describe some of the benefits of Python lists" Make sure...
"Python lists are power data structures. Describe some of the benefits of Python lists" Make sure you don't just give me a list but a few sentences instead just answering it.
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...
In this assignment, you will write a Python script to increase the population of each city...
In this assignment, you will write a Python script to increase the population of each city in the world_x database by 10% (rounded). First, add a new column to the "world_x" city table using the following MySQL command: ALTER TABLE `world_x`.`city` ADD COLUMN `Population` DOUBLE NULL DEFAULT NULL AFTER `Info`; The existing population data are stored as JSON datatype in the city table in a field named Info. You learned about JSON data types in Module 2. To obtain the...
[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...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT