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 : The cSV module
In this problem we will use the CSV module to extract information from a file containing a list of the
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 latIng coordinates, its country, and population.
Our task is a little bit strange. We are given an integer and we must find the number of cities whose
population is a multiple of That is for whom the poulation mod equals zero. With spoiler alert!
the result turns out to be That is out of the largest cities have a population that is a multiple
of Tokyo is one of them, since is a whole number.
Implement this in a function called populationismultipleof that takes as input, and returns an
integer.
Hint
Use
to skip the header line.
def populationismultipleof :
inputfile Path. resources cities.csv
numcities # counter for cities with population that is multiple of
with openinputfile as :
# write code to iterate through the file,
#
return numcities
: # Use this to check your result. You should get
populationismultipleof
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
