'''A program that allows the user to interactively enter tuition costs and display the expected year that tuition will reach that level. Author: Sean Barker Computer Science 1101''' CURRENT_YEAR = 2016 # tuition cost in the current year CURRENT_COST = 65590 # annual percentage tuition increase ANNUAL_INCREASE = 0.0386 # the prompt shown to the user when entering a future tuition cost USER_PROMPT = 'Input a target cost: ' # controls how the output is displayed to the user OUTPUT_FORMAT_STRING = 'Tuition cost is expected to exceed {0} in {1}\n' def years_until_cost(target_cost): '''Return the number of years until tuition costs are expected to exceed target_cost.''' years_passed = 0 cost = CURRENT_COST while cost < target_cost: cost += cost * ANNUAL_INCREASE years_passed += 1 return years_passed def run_prompt_loop(): '''Repeatedly prompt the user for a target cost and displays the number of years until tuition reaches that level.''' finished = False while not finished: desired_cost = input(USER_PROMPT) if desired_cost == 'quit': finished = True else: year = CURRENT_YEAR + years_until_cost(int(desired_cost)) print(OUTPUT_FORMAT_STRING.format(desired_cost, year)) def main(): '''Greet the user, run the tuition forecaster, then print an exit message.''' print('Welcome to the Bowdoin tuition forecaster!') run_prompt_loop() print('Goodbye!') main() # start the program