Write a loop that prints each country's population in country_pop. Sample output with input: 'China:1365830000,India:1247220000,United States:318463000,Indonesia:252164800': United States has...


Pyton programming question.


 I need to add a solution to the following program that defines country and pop.  I can not modify the code shown.  I am having difficulty defining country and pop without getting an error. It must be inline with the statements present but I can't modify any of the existing code.  I need to be able to iterate over the dictionary with the programming as is.


Write a loop that prints each country's population in country_pop.<br>Sample output with input:<br>'China:1365830000,India:1247220000,United States:318463000,Indonesia:252164800':<br>United States has 318463000 people.<br>India has 1247220000 people.<br>Indonesia has 252164800 people.<br>China has 1365830000 people.<br>1 user_input = input()<br>2 entries = user_input.split(',')<br>3 country_pop = {}<br>4<br>5 for pair in entries:<br>split_pair = pair.split(':')<br>country_pop[split pair[0]] = split_pair[1]<br># country_pop is a dictionary, Ex: { 'Germany': '82790000', 'France': '67190000' }<br>6<br>7<br>8<br>9<br>10 '' Your solution goes here<br>11<br>12<br>print(country, 'has', pop, 'people.')<br>

Extracted text: Write a loop that prints each country's population in country_pop. Sample output with input: 'China:1365830000,India:1247220000,United States:318463000,Indonesia:252164800': United States has 318463000 people. India has 1247220000 people. Indonesia has 252164800 people. China has 1365830000 people. 1 user_input = input() 2 entries = user_input.split(',') 3 country_pop = {} 4 5 for pair in entries: split_pair = pair.split(':') country_pop[split pair[0]] = split_pair[1] # country_pop is a dictionary, Ex: { 'Germany': '82790000', 'France': '67190000' } 6 7 8 9 10 '' Your solution goes here 11 12 print(country, 'has', pop, 'people.')

Jun 07, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here