def print_list1(list_to_print): '''print out the indices and elements of list_to_print''' for index in range(0, len(list_to_print)): element = list_to_print[index] print("list item {0} is {1}".format(index, element)) def print_list2(list_to_print): '''print out the indices and elements of list_to_print using an enumerate object''' for (index, element) in enumerate(list_to_print): print("list item {0} is {1}".format(index, element)) def years_to_100k(): '''return the numbers of years until Bowdoin tuition is expected to exceed 100k.''' years_passed = 0 # number of years that have passed cost = 61354 # 2015-16 cost annual_increase = 0.0386 # average annual increase while cost < 100000: cost *= 1 + annual_increase years_passed += 1 print("Cost in year", years_passed, "is", cost) return years_passed def printlist_range(data): '''print a list using a range loop''' for i in range(0, len(data)): print(data[i]) def printlist_while(data): '''print a list using a while loop''' index = 0 while index < len(data): print(data[index]) index += 1 def gcd(num1, num2): '''return the GCD of num1 and num2''' x = max(num1, num2) y = min(num1, num2) r = x % y while r != 0: x = y y = r r = x % y return y def prompt_gcd(): '''Repeatedly prompts the user for 2 numbers, and prints the gcd of those 2 numbers. Stops if 'exit' is entered for the first number.''' finished = False while not finished: num1 = input('Input some number: ') if num1 == 'exit': # set flag to end while loop finished = True else: num2 = input('Input another number: ') # convert input strings to ints result = gcd(int(num1), int(num2)) print("The GCD of", num1, "and", num2, "is", result)