137k views
5 votes
Can somebody help me and make a code for this in PYTHON, please? I would be very thankful!

It is estimated that China on July 1, 2019. had 1,420,062,022 inhabitants, and India 1,368,737,513. The population in China increases by 0.35% every year, and in India by 1.08%. After how many years will India surpass China in terms of population, assuming that the annual population growth in neither of these two countries will change?
I think it should be used command FOR...

User JasonWyatt
by
4.6k points

1 Answer

5 votes

Code:

population_china = 1420062022

population_india = 1368737513

years = 0

while population_china >= population_india:

population_china *= 1.0035

population_india *= 1.0108

years += 1

print(years)

Output:

6

Step-by-step explanation:

Using a while loop would probably be of greater use than a for loop since we are increasing the population growth of both countries until India's population surpasses China's population (so a condition needs to be set).

Looking at the code, we first set the original population of both countries in their own variables (population_china, population_india). We also set the 'years' variable at 0, which will increase with respect to the yearly population growths of both countries. In the while loop, the condition population_china >= population_india will allow for the variable 'years' to increase until population_india surpasses population_china. Once India's population is larger than China's population, we are left with the number of years it takes for India's population to surpass China's population, which is 6 years.

Hope this helps :)

User Rpsml
by
4.4k points