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.
# required dictionary
country_pop = {
# countries as key and numbers as value
'China': 1365830000,
'India': 1247220000,
'United States': 318463000,
'Indonesia': 252164800
}
# requied for loop to pop keys
for key in country_pop.keys():
# assign key to the country
country = key
# store the popped countries un a variable
pop = country_pop[key]
# print the required output as per the format
print(country, 'has', pop, 'people.')
Hope this is helpful. Write back to me in case you need help with your python task. I generally reply back within 24 hours. You can connect with me on Whatsapp also: +918602715108
Comments
Post a Comment