Here is my code:

def predict_population(): import math sp = input("What is the starting population? ") r = input("What is the rate of population growth (between 0 and 1)? ") while r > 1 or r < 0: print "Invalid population growth rate." r = input("Please enter a valid rate: ") t = input("How many years to predict? ") tp = sp * math.exp(r*t) print "The population after",t,"years will be",tp predict_population()

This is the result that I am aiming for:

Enter starting population: 100 Enter growth rate (a value between 0 and 1): 0.3 Enter number of years to predict: 10 Population after 0 years will be 100 Population after 1 years will be 134 Population after 2 years will be 182 Population after 3 years will be 245 Population after 4 years will be 332 Population after 5 years will be 448 Population after 6 years will be 604

This post has been edited by **Perl and Python**: 01 February 2010 - 01:32 PM