1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
LenaWriter [7]
2 years ago
10

Write a Python program that reads the CSV file, compares the population estimates of every row for 2010 and 2017 and computes th

e difference in populations as well as the percentage of change (in 2 decimal points).
Computers and Technology
1 answer:
Svetllana [295]2 years ago
3 0

Answer:

  1. import csv  
  2. with open('data.csv') as file:
  3.    records = csv.reader(file, delimiter = ",")
  4.    year = 2010
  5.    for row in records:
  6.        if (year == 2010):
  7.            print(str(year) + ": " + row[1])
  8.            previous_pop = int(row[1])
  9.            year = year + 1
  10.            print("\n")
  11.        else:
  12.            difference = abs(int(row[1]) - previous_pop)
  13.            percent = (difference / previous_pop) * 100
  14.            print(str(year) + ": " + row[1])
  15.            print("Difference: " + str(difference))
  16.            print("Percentage difference: " + str(round(percent,2)) + "%")
  17.            print("\n")
  18.            previous_pop = int(row[1])

Explanation:

Presume that there is a CSV file with 8 records. Each records have a year and population value.

Firstly, we can import the CSV module and use it to open and read the CSV file (Line 1 - 4)

Next we can use a for loop to traverse through the read data row by row (Line 6).

For the first row (year 2010), we can print out the year and population and assign the population to a variable previous_pop and increment the year by 1 (Line 9 -10).

When the year is more than 2010, we can start calculating the difference and percentage of difference of population (Line 13 -14). Then we can print out the details (Line 15 - 17) and repeat the same process in the next iteration.

You might be interested in
DES is a commonly used symmetric encryption algorithm, developed in the mid-1990s by the American government in conjunction with
In-s [12.5K]

Answer:

False

Explanation:

The DES encryption standard is believed to be weakened by the American government by containing shortened key lengths and 'S-boxes' of unknown origin.

5 0
2 years ago
A customer struggles with the small print of most smartphones. The customer still likes the idea of using a smartphone for phone
aliya0001 [1]

Answer:

The answer is a phablet.

Explanation:

A phablet is a class of smartphones with an intermediate size between a smartphone and a tablet. If the customer follows the recommendation, then he could still use this device for phone calls and work and not struggle anymore with the small print of the typical smartphone.

3 0
2 years ago
Read 2 more answers
2. Why do old video games have large pixels and images with jagged edges?
egoroff_w [7]

Answer:

A

Explanation:

cuz yea

3 0
1 year ago
What three values must be added to the ipv4 properties of a nic in order for a computer to have basic connectivity with the netw
Y_Kistochka [10]
1. The IP address

2. Subnet mask

3. Default gateway address

It’s values should be added to the NIC properties in order for the computer to have basic network connectivity. This can be done either statically or dynamically with DHCP. An additional value that should be present if the computer is to be used to connect to the Internet is the DNS server value. A computer automatically attempts to locate a DHCP server if configured to do so. A DHCP server address is not used. Finally, NAT is configured on a router, not on a computer host, and speed and duplex settings are NIC hardware settings and not IPv4 properties of the NIC.
8 0
2 years ago
Etapas del desarrollo​
cestrela7 [59]

Answer:

Las etapas del desarrollo humano

Etapa prenatal. Comprende desde la concepción hasta el parto. ...

Etapa de la niñez. Es la comprendida entre el nacimiento y los tres años. ...

Primera infancia. Desde los 3 a los 6 años. ...

Infancia intermedia. ...

Adolescencia. ...

Etapa adulta temprana.

Edad adulta intermedia.

Edad adulta tardía.

Explanation:

5 0
2 years ago
Other questions:
  • Consider a file system that uses inodes to represent files. Disk blocks are 2KB in size and a pointer to a disk block requires 4
    13·1 answer
  • What is the inverse function of d(x ) = -2x - 6?
    11·1 answer
  • Which of the following is a technique used by hackers to identify unsecured wireless network locations to other hackers?A. Blues
    10·1 answer
  • Many computer programs contain ____ that detail the specific instructions a computer should perform (in a specific order) to car
    9·1 answer
  • Write a program that first reads in the name of an input file, followed by two strings representing the lower and upper bounds o
    8·1 answer
  • In C, how could I use a command line input to remove certain characters from an existing string? For example, if I have string '
    8·1 answer
  • Which of the following is a precaution that helps to protect you from electric shock when working with electric power tools?
    7·2 answers
  • Please someone helpp
    12·2 answers
  • SOMEONE PLEASE HELP ME WITH THIS PLEASE HELP ME PLEASE!!!!!!
    6·1 answer
  • Gabby is creating a game in which users must create shapes before the clock runs out. Which Python module should Gabby use to cr
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!