Ask Question
23 July, 01:43

Write a loop that prints each country's population in country_pop. Sample output with input:

United States has 318463000 people.

India: 1247220000

Indonesia: 252164800

China: 1365830000

1. country_pop = {

2. 'China': 1365830000

3. 'India': 1247220000

4. 'United States': 318463000

5. 'Indonesia': 252164800

6. } # country populations as of 2014

7

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

+5
Answers (1)
  1. 23 July, 04:34
    0
    country_pop = { 'China': 1365830000, 'India': 1247220000, 'United States': 318463000, 'Indonesia': 252164800 } for key in country_pop: print (key + " has " + str (country_pop[key]) + " people")

    Explanation:

    The solution code is written in Python 3.

    Given a dictionary, country_pop with data that includes four country along with their respective population (Line 1-6). We can use for in loop structure to traverse through each of the key (country) in the dictionary and print their respective population value (Line 7-8). The general loop structure through is as follow:

    for key in dict:

    do something

    One key will be addressed for each round of loop and we can use that key to extract the corresponding value of the key (e. g. country_pop[key]) and print it out.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a loop that prints each country's population in country_pop. Sample output with input: United States has 318463000 people. India: ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers