# average annual tuition increase (3.86%) ANNUAL_INCREASE = 0.0386 # tuition cost 2015-16 COST_2015 = 61354 def years_to_cost_iter(cur_cost, target_cost): '''Return the numbers of years until Bowdoin tuition will reach target_cost, assuming the current cost is cur_cost. ITERATIVE implementation.''' years_passed = 0 cost = cur_cost while cost < target_cost: cost *= 1 + ANNUAL_INCREASE years_passed += 1 return years_passed def years_to_cost(cur_cost, target_cost): '''Return the numbers of years until Bowdoin tuition will reach target_cost, assuming the current cost is cur_cost. RECURSIVE implementation.''' if cur_cost >= target_cost: # base case return 0 else: # recursive case next_cost = cur_cost + ANNUAL_INCREASE * cur_cost return 1 + years_to_cost(next_cost, target_cost) def main(): '''Prompt for a future cost, then calculate how many years it will take for tuition to reach that cost.''' print("Current cost is ${0}".format(COST_2015)) future_cost = int(input("Enter a future cost: ")) years = years_to_cost(COST_2015, future_cost) print("Tuition will reach ${0} in {1} years".format(future_cost, years)) main()