Answer to Question #304358 in Python for nick

Question #304358

Write the python program using only the import CSV to display the following:

  1. Count and display the number of cities per country.
  2. Count and display the country which is a member of the EU (EU = yes) and not a member of the EU (EU = no).
  3. Find and display the country with the highest and lowest total population.
  4. Count and display the country with a coastline (coastline = yes) and without a coastline (coastline = no)


https://drive.google.com/file/d/1OnN0RCvpVJ3A4x02DAOxWNSxJwJmJfm9/view?usp=sharing


NOTE:

DON'T USE ANY DIFFERENT MODULE, JUST IMPORT CSV

1
Expert's answer
2022-03-02T15:34:14-0500
import csv

with open('data.csv', newline='') as csvfile:
  reader = csv.DictReader(csvfile)
  city = ''
  for row in reader:
    count = 0
    if city != row:
      city = row
      for i in reader:
        if city == i['country']:
          count=count+1
   print(city, ':', count)
 

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS