Ask Question
30 April, 09:38

Write a loop that prints each country's population in country_pop. Sample output for the given program.

United States has 318463000 people.

India has 1247220000 people.

Indonesia has 252164800 people.

China has 1365830000 people.

country_pop = {

'China': 1365830000,

'India': 1247220000,

'United States': 318463000,

'Indonesia': 252164800

} # country populations as of 2014

print (country, 'has', pop, 'people.')

+4
Answers (1)
  1. 30 April, 10:27
    0
    Correct code for the above question which is written after the defined list to display the output.

    for x, y in country_pop. items () : #for loop to prints the list items.

    print (str (x) + " has "+str (y) + " people") #print function to print the value.

    Output:

    The above code is in python language which display the output as the above question demands.

    Explanation:

    The above question code is written in python language to display the result, but this code is not correct. The above code needs a 'for' loop, which will render the list item one by one. The above-list defined in the form of key-value pair, So there is a need for the ''item" function which is the part of the python dictionary to display the list items. There also needs to define the two variables in the for loop, one is for key and the other is for value.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a loop that prints each country's population in country_pop. Sample output for the given program. United States has 318463000 people. ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers