65.3k views
1 vote
(Population projection) The US Census Bureau projects population based on the

following assumptions:

One birth every 7 seconds

One death every 13 seconds

One new immigrant every 45 seconds

Write a program to display the population for each of the next five years. Assume the

current population is 312032486 and one year has 365 days. Hint: in Python, you

can use integer division operator // to perform division. The result is an integer. For

example, 5 // 4 is 1 (not 1.25) and 10 // 4 is 2 (not 2.5).



Here's what I have but I kept getting wrong numbers... what am I doing wrong?



# Total Population: 312032486



# Total Seconds/Year: 365* 24 * 60 * 60 = 31536000



# Births/Year: 31536000/7 = 4505142.857142857



# Deaths/Year: 31536000/13 = 2425846.153846154



# Immigrations/Year: 31536000/45 = 700800.0



print((312032486) + (4505142.857142857 + 700800 - 2425846.153846154) // 1 )



print((312032486) + (2 * (4505142.857142857 + 700800 - 2425846.153846154)) // 1 )



print((312032486) + (3 * (4505142.857142857 + 700800 - 2425846.153846154)) // 1 )



print((312032486) + (4 * (4505142.857142857 + 700800 - 2425846.153846154)) // 1 )



print((312032486) + (5 * (4505142.857142857 + 700800 - 2425846.153846154)) // 1 )

User Oona
by
4.4k points

1 Answer

7 votes

Step-by-step explanation:

I have provided the code below which is producing the correct answers. Answers are verified by actual answers from calculator.

I have used a for loop for fast calculation and print.

ANSWER CODE:

population = 312032486;

seconds = 365*24*60*60;

births = seconds//7;

deaths = seconds//13;

immigrations = seconds//45;

years = {1,2,3,4,5}

change_in_pop = births - deaths + immigrations;

for val in years:

new_population = population + val*(change_in_pop)

print("The population after " + str(val) + " years is " + str(new_population)+"\\")

User SimplyKiwi
by
4.3k points