Getting started with python
Paul Rubin
http
Sun Apr 15 21:19:17 EDT 2007
Steve Holden <steve at holdenweb.com> writes:
> You'd be worth more if you'd used elif and omitted the continue
> statements, but for a first solution it's acceptable.
>
> For better readability I'd have used
> if i % 5 == 0
I think I'd be more concerned about getting rid of the i%15 test.
What if a few more words get added?
def fizzbuzz(n):
words = ((3, 'Fizz'), (5, 'Buzz'), (7, 'Jazz'), (11, 'Pizzazz'))
r = ''.join(b for a,b in words if n%a == 0)
return r or str(n)
for i in xrange(1,101):
print fizzbuzz(i)
More information about the Python-list
mailing list