Back to home

Python Fizzbuzz main image

Python Fizzbuzz

Test file

Create file fizz_buzz_test.py:

import unittest import fizz_buzz class FizzBuzzTest(unittest.TestCase): def test_capitalise_sentence(self): assess = [ { "input": 2, "expectation": 2 }, { "input": 3, "expectation": "Fizz" }, { "input": 5, "expectation": "Buzz" }, { "input": 15, "expectation": "FizzBuzz" }, ] for test in assess: self.assertEqual(fizz_buzz.run( test["input"]), test["expectation"]) if __name__ == '__main__': unittest.main()

FizzBuzz

Create file fizz_buzz.py.

def run(arg): if arg % 5 == 0 and arg % 3 == 0: return "FizzBuzz" elif arg % 3 == 0: return "Fizz" elif arg % 5 == 0: return "Buzz" else: return arg

Running tests

Change into directory and run python3 -m pytest -v fizz_buzz_test.py.

Personal image

Dennis O'Keeffe

@dennisokeeffe92
  • Melbourne, Australia

Hi, I am a professional Software Engineer. Formerly of Culture Amp, UsabilityHub, Present Company and NightGuru.
I am currently working on Visibuild.

1,200+ PEOPLE ALREADY JOINED ❤️️

Get fresh posts + news direct to your inbox.

No spam. We only send you relevant content.