Data function:
def readData():
file_object = open("countries.csv", "r")
alldata = file_object.readlines()
data = []
for lines in alldata:
lines = lines.strip()
linecollection = lines.split(",")
linecollection[2]
=int(linecollection[2])
linecollection[3]
=int(linecollection[3])
linecollection[4]
=int(linecollection[4])
data.append(linecollection)
return data
file_object.close()
Continents function(Still need help with this)
Problem #2: Find the Continents Write a function findContinents
which takes the variable called “data” (returned by the function
readData above) as a parameter and returns a list of the continents
called “continents”. Call the function and print the list returned.
Note that in this data, North and South America are considered a
single continent called “Americas” and Antarctica is omitted since
it contains no countries.
Problem #5: Find the Average Per Capita GDP of the Countries on
Each Continent Write a function findAveragePerCapitaGDP that takes
the variables “data” and “continents” produced by the first two
functions above and returns a list containing the average per
capita GDP for all the countries on each continent. Call the
function and print the list returned. The list should be in the
same order as the continents appear in the “continents” list. So,
for instance, if “Europe” is the first item in your list of
continents, then the average per capita GDP for the countries in
Europe should be first in the list returned by
findAveragePerCapitaGDP. You will need to produce a list containing
the number of countries per continent to help you to solve this
problem
language: Python
Data function: def readData(): file_object = open("countries.csv", "r") alldata = file_object.readlines() da
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Data function: def readData(): file_object = open("countries.csv", "r") alldata = file_object.readlines() da
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!