def years_to_double(money, rate): '''Return how many years it takes for an investment to double at a given interest rate.''' years = 0 # Each year until the investment has doubled, add # interest for the year. while money != (money * 2): years += 1 money += rate * money return years if __name__ == "__main__": # How many years will it take to turn 10 dollars into 20 dollars # if 10% interest is added every year? interest = 0.1 investment = 10 years = years_to_double(investment, interest) print "At an interest rate of " + str(interest), print "your money will double in " + str(years) + " years."