FizzBuzz: Difference between revisions

Content added Content deleted
(Added C# Implementation)
(→‎{{header|Python}}: wrap examples in python tags)
Line 591: Line 591:
</pre>
</pre>
=={{header|Python}}==
=={{header|Python}}==
<pre>
<python>
for i in xrange(1, 101):
for i in xrange(1, 101):
if i % 15 == 0:
if i % 15 == 0:
Line 601: Line 601:
else:
else:
print i
print i
</pre>
</python>


And a shorter version with less duplication:
And a shorter version, using a list comprehension and logical expressions for less verbosity:
<pre>
<python>
for i in range(1, 101):
for i in range(1, 101):
words = [word for n, word in ((3, 'Fizz'), (5, 'Buzz')) if not i % n]
words = [word for n, word in ((3, 'Fizz'), (5, 'Buzz')) if not i % n]
print ''.join(words) or i
print ''.join(words) or i
</pre>
</python>


=={{header|RapidQ}}==
=={{header|RapidQ}}==