def gcd(num1, num2): '''Returns 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 gcd_interactive(): '''Repeatedly prompts the user for two numbers, then displays their GCD. The user can end the prompts by entering 'quit' for the first number.''' finished = False while not finished: num1 = input('Input a number: ') if num1 == 'quit': finished = True else: num2 = input('Input a second number: ') result = gcd(int(num1), int(num2)) print('The GCD of {0} and {1} is {2}'.format(num1, num2, result)) print('all done!') def file_city_sum(): '''Sums the population of a number of cities listed in a file.''' file = open('population.txt') # open a file object total_pop = 0 for line in file: # loop through the lines of the file parts = line.split() city_name = parts[0] city_pop = int(parts[1]) total_pop += city_pop file.close() print('Total population is', total_pop)