The World in 2050

Did you know that the world population increased from 1 billion in 1800 to around 8 billion today. And it’s still growing, even though the growth rate has declined from 2% per year around 50 years ago to approximatively 1% per year nowadays.

The aim of this challenge is going to use a Python script to estimate the growth of the world population over the next decades and to predict in which year, will the world population reach 10 billion.

We will base our projections using a static growth rate of 1% per year. (In reality, currently this growth rate is declining slightly every year). We will also start our projections using an estimate of the world population of 7,850,000,000 in 2022.

Step 1: Estimatig next year’s population

Considering a 1% population growth per year, we can use the following formula to estimate next year’s population:

next year population = current population x 1.01

So we can implement this formula using Python:

Step 2: Using iteration…


Let’s use an infinite loop to predict the growth of the world population in the coming years.
In Python we can implement an infinite loop using a while True: instruction.

To see the impact of our loop, we will pause for 1 second for each iteration. We will do so using the sleep() function from the time library.

Step 3: Stopping when the population reach 10 billion…

Instead of running an infinite loop, we will run a loop that stops iterating as soon as the world population reaches or exceeds 10 billion.

We will use a condition in our while loop as follows:
while population<10000000000:

Only showing the final result…

As the aim of this challenge was to find out in which year the world population will reach 10 billion, we do not need to output the world population for every single year. By unindenting our output (print instruction), we are taking this instruction away from the loop. So this instruction will only run once, after the while loop. We can also remove our pause (sleep) instruction to produce a response without delay.

Your turn…

Use the above code in your IDE or using trinket.io.

Extension Task 1: The World in 2050

Tweak the code provided above so that instead of stopping when the population reaches 10 billion, the code (loop) stops when the year reaches 2050, in order to just output the world population in 2050.

Extension Task 2: The World and You!

Tweak this code, so that the program first asks for the end-user to enter their age.
Then the program should output the projection of both the world population and of the end-user’s age over the next 50 years. For instance, for an end-user who is eighteen in 2022, the output of your program should look like this:

    “In 2023, the world population will be 7928500000 and you will be 19 years old.”
    “In 2024, the world population will be 8007785000 and you will be 20 years old.”
    “In 2025, the world population will be 8087862850 and you will be 21 years old.”
    …and so on.

Extension Task 3: How many more inhabitants in 2050?

Adapt your code, for the program to calculate and output how many more inhabitants there will be on planet Earth, in 2050, compared to 2022.

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area
Tagged with: