1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
MAXImum [283]
3 years ago
4

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.
Computers and Technology
1 answer:
Anika [276]3 years ago
7 0

Answer:

Hi there! This question is good to check your understanding of loops. To illustrate, I have implemented the answer in Python and explained it below.

Explanation:

Assuming user input for the country and population list as provided in the question, we can write the python script "country_pop.py" and run it from the command line. First we prompt user for the input, after which we split the country-population list which is separated or delimited with a comma into an array of country-population list. We then create a hash of country and its corresponding population by further splitting the country-population combo into a hash, and finally, printing the resultant hash as the output.    

country_pop.py

def add_country_pop(country, population):

 countrypop_hash[country]=population

countrypop_hash = {}

input_string = input("Enter country population list: ")

print(input_string)

countrypop_array = input_string.split(",")

for country in countrypop_array:

 country_pop = country.split(':')

 pop_country = country_pop[0]

 population = country_pop[1]

 add_country_pop(pop_country, population)

 print(country + ' has ' + population + ' people')

Output

> country_pop.py

Enter country population list: China:1365830000,India:1247220000,United States:318463000,Indonesia:252164800

China:1365830000,India:1247220000,United States:318463000,Indonesia:252164800

China:1365830000 has 1365830000 people

India:1247220000 has 1247220000 people

United States:318463000 has 318463000 people

Indonesia:252164800 has 252164800 people

You might be interested in
Explain how abstraction is used in a GPS system?
zhenek [66]
I hope that this answer will help u to solve your problem. But u have tto take the importance clues only .

5 0
4 years ago
Which type of formatting would you apply to spreadsheet data so that each cell is outlined?
rjkz [21]

Answer:

D. Border

Explanation:

Edge 2020

5 0
3 years ago
The main reason to set a field size in access is to:
Nadya [2.5K]
The main reason to set a field size in access is to limit the lengths of value in the table.
Field size determines the limits or determines the maximum of text that can be input in the text or number field. Also, it may reduce data entry errors in changing the field size in access.
4 0
4 years ago
Lesson 9 looping and random numbers
Pavlova-9 [17]

Answer:

??????????????????????????????????????????////

Explanation:

8 0
3 years ago
Pasahot ako plzsss kailangan ko na ngayon ​
goldfiish [28.3K]

Answer:

what language is this

Explanation:

3 0
3 years ago
Other questions:
  • To differentiate the absolute pathnames to files that are located on different drives, html requires you to include the drive le
    8·1 answer
  • What is an example of a good URL?
    7·2 answers
  • A(n) __________ can include a computer's full operating system, applications, and system settings, including security and config
    7·1 answer
  • How can an individual find career data?
    13·1 answer
  • TRUE OR FALSE! HELP!!
    13·1 answer
  • 50 POINTS<br><br>Question linked in file below.
    5·1 answer
  • Write a program that reads a list of integers into a list as long as the integers are greater than zero, then outputs the smalle
    11·1 answer
  • Which bug type would you suggest for the following bug? The button label "Add to cart" is not fully visible.
    5·1 answer
  • Commercial technical data and commercial software:_________.
    11·1 answer
  • Your company is building a new architecture to support its data-centric business focus. You are responsible for setting up the n
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!