Ask Question
7 February, 13:56

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.')

+4
Answers (1)
  1. 7 February, 13:58
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers