Part III: Population Data (20 points) -populations that takes five arguments, in
ID: 3740408 • Letter: P
Question
Part III: Population Data (20 points) -populations that takes five arguments, in this order: amcuatinent: one of the following strings: Afeica. "Anericas.'Asia".Europe or Oceania 2.min.gdp: a positive integer 3, countrles: a dictionary that maps a continem name to a list of some of the countries in thl continent 4. gdips: adictionary that maps a counery name to that country's GDP (gross domestic prodact) in millions USD (SMM) populations: a dictiosary that maps a country ame to its population CSE 101-Spring 2018 Homework 4 Page 4 Here are sample argaments that could be passed to the function I which.cont inent -Africa 2 min.gdp- 1529760 3. countries- Anericas':["ArgentinaUruguayBrazi1'.Puerto Rico.Panana 1 Oceania 'PAuatraliaNe ealand Fapua New Guinea'l Africa 'Senegaltesotho"South Africa.TogoSierza Leone'1 Europe": 'Norway".Greece*1 Argentina. : 545866,"Uruguay'? 52420, .Brazil'? 1796186. Puerto Rico 103135. Panana55188 P:4632 Australia1204616 New Zealand 185017 Papua New Guinea' 16929 Myanmar 67430 Isael:318744, 'Senegal 14765, Lesotho:2200, South Atrica' 294841, Togo:4400 Siezra Leone 3669 Norway":370557, Greece194559 5. populations-' Argent ina 43847430 Uuguay' 3444006 Brazil 207652865 Puerto Rico'1 3667903, Panana'1 4034119 FIIL' 898760 Australia' 24125848, New Zealand 4660833 Papua New Guinea 8084991Hyanmar'1 52885223 Israel'1 8191828 Senegal 15411 'Togo 7606374, Sierza Leone'7396190Norway 5254694 Greece:11183716) 614. Lesotho: 2203821. South Africa 56015473 Using the given argumenes, the function computes and retums the sum of populations of all counaries that are located in continent and which hane a GDP thut is grealer than or oqual to in.gdp For example, suppose which.cont inent Anericas andmin.gdp - 1000000. The function would consult the countries dictionary to get a list of countries from the American. It would then consulh the gops dictionary to find all countries with a GDP of a least $1,000,00OM and add topother the populations of all sch countries CSE 101-Spring 2018 Pape SExplanation / Answer
Answer:-
According to given question the code is shown below
PYTHON CODE:-
#Define the function
def sumpopulations(whichcontinent, mingdp, countries, gdps, populations):
#Loop to get the countries in the given continent
for key in countries:
#If continent matches
if key == whichcontinent:
#Get the list of countries in the continent
listCountry = (countries[key])
#List to store the countries having mingdp
selectedCountry = []
#For countries in the given continent
for country in listCountry:
#Loop to check for gdps
for key in gdps:
#If countris matches
if key == country:
#If country has mingdp
if gdps[key] >= mingdp:
#Select that country
selectedCountry.append(country)
#Initialize sum
sumPop = 0
#Loop to find sum of populations for countries having mingdp
for country in selectedCountry:
#Loop to check country in the populations dictionary
for key in populations:
#If country matches
if key == country:
#Add the populations to the total
sumPop += populations[key]
#Return the sum
return sumPop
#Sample Run
#Set the continent
whichcontinent = 'Americas'
#Set the mingdp
mingdp = 100000
#Define countries
countries = {
'Americas': ['Argentina', 'Uruguay', 'Brazil', 'Puerto Rico', 'Panama'],
'Oceania': ['Fiji','Australia', 'New Zealand', 'Papua New Guinea'],
'Asia': ['Myanmar', 'Israel'],
'Africa': ['Senegal', 'Lesotho','South Africa', 'Togo', 'Sierra Leone'],
'Europe': ['Norway', 'Greece']
}
#Define gdps
gdps = {
'Argentina':545866, 'Uruguay':52420, 'Brazil':1796186,
'Puerto Rico':103135, 'Panama':55188, 'Fiji':4632,
'Australia':1204616, 'New Zealand':185017, 'Papua New Guinea':16929,
'Myanmar':67430, 'Israel':318744, 'Senegal':14765, 'Lesotho':2200,
'South Africa':294841, 'Togo':4400, 'Sierra Leone':3669,
'Norway':370557, 'Greece':194559
}
#Define populations
populations = {
'Argentina':43847430, 'Uruguay':3444006,
'Brazil':207652865, 'Puerto Rico':3667903, 'Panama':4034119,
'Fiji':898760, 'Australia':24125848, 'New Zealand':4660833,
'Papua New Guinea':8084991, 'Myanmar':52885223, 'Israel':8191828,
'Senegal':15411614, 'Lesotho':2203821, 'South Africa':56015473,
'Togo':7606374, 'Sierra Leone':7396190,'Norway':5254694,
'Greece':11183716
}
#Call function to find the populations for the given mingdp
totPop = sumpopulations(whichcontinent, mingdp, countries, gdps, populations)
#Print message
print("Total populations:" )
#Print total population
print(totPop)