""" maximum.py Problem 4, chapter 13 Zelle's book Write and test a recursive function to find the maximum value in a list. Hint: The max is the larger of the 1st and the rest. $ python maximum.py DEBUG comparing 22 with max([16]) DEBUG comparing 10 with max([22, 16]) DEBUG comparing 2 with max([10, 22, 16]) DEBUG comparing 5 with max([2, 10, 22, 16]) DEBUG comparing 3 with max([5, 2, 10, 22, 16]) max of [3, 5, 2, 10, 22, 16] is 22 """ def maximumBruteForce(numbers): biggest = -1000000 # smaller than our numbers for n in number: if n > biggest: biggest = n return biggest def maximumRecursive(numbers): if len(numbers) == 1: return numbers[0] else: a = numbers[0] b = maximumRecursive(numbers[1:]) print " DEBUG comparing {} with max({})".format( a, numbers[1:]) if a > b: return a else: return b digits = [3, 5, 2, 10, 22, 16] answer = maximumRecursive(digits) print "max of {} is {}".format(digits, answer)