James Stroud <[EMAIL PROTECTED]> writes: > 1. This doesn't act according to the specification if you add, for > example, (2, 'Zonk'). Now 30 gives 'ZonkFizzBuzz' and not 'FizzBuzz' > according to the specification.
Correct, the original specification only had 3 and 5. I gave a longer example to illustrate how the specification might be modified. Obviously it is not the same specification any more. The i%15 approach gets messy once there are more than two numbers to check. > So, I would keep my original explicit testing: > def fizzbuzz(n): > words = ((30, 'Whammo'), (15, 'FizzBuzz'), > (5, 'Fizz'), (3, 'Buzz'), (2, 'Zonk')) > for k,v in words: > if not k % n: > return v > return n I don't think that's in the spirit of the original, which would be to print 'BuzzZonk' for n=6. -- http://mail.python.org/mailman/listinfo/python-list