Getting started with python

Paul Rubin http
Sun Apr 15 23:43:30 EDT 2007


James Stroud <jstroud at mbi.ucla.edu> 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.



More information about the Python-list mailing list