Write a program that will predict the size of a population of organisms. The program should ask the user for the starting number of organisms, their average daily population increase (as a percentage, expressed as a fraction in decimal form: for example 0.052 would mean a 5.2% increase each day), and the number of days they will multiply. A loop should display the size of the population for each day.

Respuesta :

Answer:

  1. import math
  2. start_pop = int(input("Enter start population: "))
  3. daily_increase = float(input("Daily population increase: "))
  4. num_days = int(input("Number of day multiplied: "))
  5. pop_size = start_pop  
  6. for i in range(1, num_days+1):
  7.    pop_size += pop_size * daily_increase  
  8.    print("Day " + str(i) + ": " + str(math.floor(pop_size)))

Explanation:

The solution code is written in Python 3

Since we wish to round the population size to integer, we need to import math module to use its floor method in a later stage (Line 1)

Next, prompt user input for start population, daily increase percent and number of day they will multiply (Line 2 -4)

Next create a variable pop_size and set the start_pop as initial value

Create a for loop that run num_days of rounds and within the loop apply the formula to increase the population size based on the daily_increase rate and print it to console (Line 8 -10).

ACCESS MORE
EDU ACCESS
Universidad de Mexico