CS 125
Homework 4

Assignment hw4
Files pop1.py, pop2.py
Due 4:00 pm Wed Oct 20

Part 1

The exponential model of population growth assumes that in a given time period (day, week, month, etc) a population increases at a constant rate. So if the population is P and the rate of increase is r, then the population at the end of the time period is P + P * r.

Write a program that inputs the initial population, the percentage rate of increase, and a number of time periods. It will print the population at the end of those time periods. Since the rate is given as a percentage, you have to divide it by 100. Use a for loop and round the answer to the nearest integer.

Sample runs:

> python pop1.py
Enter the initial population: 1000
Enter the percentage growth rate per time period: 10
Enter the number of time periods: 25
The final population is:  10835
> python pop1.py
Enter the initial population: 450
Enter the percentage growth rate per time period: 7
Enter the number of time periods: 1000
The final population is:  108890551899456265725683605438464

Part 2

Write a program that inputs the initial population, the percentage rate of increase, and a final population. It will print the number of time periods required to reach the final population and the actual population reached. Use a while loop. Hint: you have to count.

Sample runs:

> python pop2.py
Enter the initial population: 1000
Enter the percentage growth rate per time period: 10
Enter the desired final population: 1000000
After 73 periods the population will be: 1051153
> python pop2.py
Enter the initial population: 1
Enter the percentage growth rate per time period: 1
Enter the desired final population: 1000000000
After 2083 periods the population will be: 1003278693