# Test-driven development from ucb import trace, interact def gcd(m, n): """Return the largest k that evenly divides both m and n. k, m, and n are all positive integers. >>> gcd(12, 8) 4 >>> gcd(16, 12) 4 >>> gcd(16, 8) 8 >>> gcd(2, 16) 2 >>> gcd(24, 42) 6 >>> gcd(5, 5) 5 """ if m == n: return m elif m < n: return gcd(n, m) else: return gcd(m-n, n) # Decorators def trace1(fn): """Return a function equivalent to fn that also prints trace output. fn -- a function of one argument. """ def traced(x): print('Calling', fn, 'on argument', x) return fn(x) return traced @trace1 def square(x): return x*x @trace1 def sum_squares_up_to(n): total, k = 0, 1 while k <= n: total, k = total + square(k), k + 1 return total