Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Question 2 Given two lists, a list of countries and the list of percentages of the world's population for each country (at the same/corresponding index),
Question 2 Given two lists, a list of countries and the list of percentages of the world's population for each country (at the same/corresponding index), as follows: countries ["Brazil", "China", "India","Indonesia", "Japan", "Mexico", "Nigeria", "Pakistan", "Russia", "United States"] popPercent = [2.73, 18.47,17.7,3.51,1.62,1.65,2.64,2.83,2.87,4.2] Note: The data is obtained from https://www.worldometers.info/world-population/population-by-country/ Sort the lists based on the ascending order of the population percentage as follows: countries = ['Japan', 'Mexico', 'Nigeria', 'Brazil', 'Pakistan', 'Russia', 'Indonesia', 'United States', 'India', 'China'l pop Percent = [1.62, 1.65, 2.64, 2.73, 2.83, 2.87, 3.51, 4.2, 17.7, 18.47] Note that the sorting the popPercent list means also moving the corresponding country to the correct corresponding index in its list. Your program should include the following functions: function main which initializes the two lists, countries and pop Percent, as shown above o prints the unsorted lists activate Wind sorts the pop Percent list from smallest to largest and its corresponding country names in the countries list, using a loop and two functions as follows: countries list, using a loop and two functions as follows: find the smallest percentage in the unsorted portion of the popPercent list using the function indexOfSmallest swap the smallest percentage (and the associated country name) found in the popPercent list with the value at the start of the unsorted portion of the list list using the function swapValues o prints the sorted lists in columns (see sample output below) function indexOfSmallest which, given the list popPercent and the start position of the unsorted portion of the list, finds and returns the index of the smallest value in the unsorted portion of the list function swapValues which, given the two lists (countries and popPercent), the position of the smallest population value found and the position of the start of the unsorted portion of the list, swaps the values at those two position, thereby placing the smallest value (and corresponding country name) in sorted order The sample output is as follows: Unsorted lists... Countries: ['Brazil', 'China', 'India', 'Indonesia', 'Japan', 'Mexico', vate Wind 'Nigeria', 'Pakistan', 'Russia', 'United States'] & World Population: [2.73, 18.47, 17.7, 3.51, 1.62, 1.65, 2.64, 2.83, D Unsorted lists... Countries: ['Brazil', 'China', 'India Indonesia, "Japan', 'Mexico', Nigeria', 'Pakistan', 'Russia', 'United States! | % World Population: [2.73, 18.47, 17.7 3.511.62, 1.65, 2.64, 2.83, 2.87, 4.2] Sorted lists... Number Country 1 Japan 2 Mexico 3 Nigeria 4. Brazil 5 Pakistan 6 Russia 7 Indonesia 8 United States India 10 China % Population 1.62 1.65 2.64 2.73 2.83 2.87 3.51 4.20 17.70 18.47 Call the file containing your program sort Populations.py
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started