In: Computer Science
Program #2: Population Increase
Ask the user to give the starting population, a percent yearly increase, and the number of years to display. Then display in a neat table the results. (Note: A percentage value for each year will often not yield a whole number, so we must round to the nearest whole value) You must use a loop of some sort to output the table. Again start and end your programs with friendly messages.
Please find below the code, code screenshots and output screenshots. Please refer to the screenshot of the code to understand the indentation of the code. Please get back to me if you need any change in code. Else please upvote
CODE:
print("Let's calculate the population Increase\n") #friendly message at start
population = int(input("Enter the starting population: ")) #Reading the starting population
percent_increase = float(input("Enter yearly increse as percentage: ")) #Reading the yearly increase
num_years = int(input("Enter the number of years to display: ")) #Reading thye number of years to display
print("\nYear Increase Population") #printing table header
year = 1 #Initialize year as 1
while year <= num_years: #Loop for num_years times
increase = round((population * percent_increase)/100) #calculate the increase in population
population = population + increase #calculate the total population
print("{:>2d} {:>5d} {:>5d}".format(year, increase, population)) #displaying increase and population for each year
year = year + 1 #increment year by 1
print("\nGoodbye!!!") #friendly message at end
OUTPUT: