Question: 2. Estimating The World Population (5 points) The webcomic xkcd gives the following formula to approximate the world population for a given year (from 2000

2. Estimating The World Population (5 points)

The webcomic xkcd gives the following formula to approximate the world population for a given year (from 2000 onward):

a. Obtain the last two digits of the year (this value is just the year modulo 100).

b. Calculate the number of leap years (including the current year) since Hurricane Katrina (2005). You can approximate this by dividing the difference in years by 5, then adding 1 to the quotient. For example, if the current year is 2016, we subtract 2005 to get the difference (which is 11). We divide the difference by 5 using floor division (11 // 5 becomes 2). Finally, we add 1 (giving us a final value of 3).

c. Subtract the result of step (b) from your answer to step (a).

d. Divide the previous result by 10.0 (use regular division, not floor division), then add 6 to get your final answer.

This gives the approximate world population in billions of people.

Define a Python function named population() that takes a single integer argument representing a year (you may assume that the year is always greater than or equal to 2000). Your function should use the formula above to calculate and return a new number representing the estimated world population for that year in billions.

Finally, following your function definition, write some Python code that reads in a year from the user, calls your population() function with that value, and prints the value returned by the function.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!