def print_table(row_size, col_size): '''Print a multiplication table with the specified number of rows and columns.''' for row_num in range(1, row_size + 1): for col_num in range(1, col_size + 1): print(col_num * row_num, end='\t') print() # end the line def tuition_cost_calculator(target): '''Return the number of years until tuition is expected to reach the given target.''' cost = 65590 # 2016-2017 cost annual_increase = 0.0386 # average increase per year years = 0 while cost < target: cost += cost * annual_increase years += 1 print("Cost in year {0} is ${1:.0f}".format(2016 + years, cost)) print("{0} years until 100k".format(years)) def loop_examples(): '''Examples of equivalent loops.''' data = [3, 10, 5, 2] # Version 1: for each loop for item in data: print(item) # Version 2: range loop for i in range(0, len(data)): print(data[i]) # Version 3: while loop index = 0 while index < len(data): print(data[index]) index += 1 def doubles_to_100(num): '''Return how many times you'd have to double num for it to reach 100. E.g., doubles_to_100(20) = 3''' count = 0 while num < 100: num *= 2 count += 1 return count