Skip to content

Instantly share code, notes, and snippets.

@mattyw
Created July 16, 2011 11:51
Show Gist options
  • Save mattyw/1086293 to your computer and use it in GitHub Desktop.
Save mattyw/1086293 to your computer and use it in GitHub Desktop.
The Fizzbuzz kata in Python
import unittest
def fizzbuzz(value):
if value % 5 == 0 and value % 3 == 0:
return 'fizzbuzz'
elif value % 5 == 0:
return 'buzz'
elif value % 3 == 0:
return 'fizz'
else:
return value
class FizzBuzzTest(unittest.TestCase):
def setUp(self):
pass
def test_fizz(self):
self.assertEqual('fizz', fizzbuzz(3))
def test_value(self):
self.assertEqual(2, fizzbuzz(2))
def test_buzz(self):
self.assertEqual('buzz', fizzbuzz(5))
def test_fizzbuzz(self):
self.assertEqual('fizzbuzz', fizzbuzz(15))
if __name__ == '__main__':
unittest.main()
#for x in xrange(1,101):
# print fizzbuzz(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment