Question: Question 2 : The cSV module In this problem we will use the CSV module to extract information from a file containing a list of

Question 2: The cSV module
In this problem we will use the CSV module to extract information from a file containing a list of the 1,000
largest cities in the world. Loading the file into a spreadsheet program (like Excel) we can see the first few
rows of the table:
The first line of the file is the header line -- we will skip that line when processing the file. The columns of
the table are the city's name, its lat/Ing coordinates, its country, and population.
Our task is a little bit strange. We are given an integer x and we must find the number of cities whose
population is a multiple of x. That is, for whom the poulation mod x equals zero. With x=8(spoiler alert!)
the result turns out to be 315. That is,315 out of the 1,000 largest cities have a population that is a multiple
of 8. Tokyo is one of them, since 37,732,000/8 is a whole number.
Implement this in a function called population_is_multiple_of that takes x as input, and returns an
integer.
Hint
Use
to skip the header line.
def population_is_multiple_of (x) :
inputfile = Path. )/'resources '/'1000cities.csv'
num_cities =0, # counter for cities with population that is multiple of x
with open(inputfile,...) as f :
... # write code to iterate through the file,
#
return num_cities
[7]: # Use this to check your result. You should get 315
population_is_multiple_of (8)
 Question 2: The cSV module In this problem we will use

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!