{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# [Fizz Buzz](https://en.wikipedia.org/wiki/Fizz_buzz)\n",
"\n",
"> Fizz buzz is a group word game interview question for children software developers to teach them about division flow control. Players take turns...replacing any number divisible by three with the word \"fizz\", and any number divisible by five with the word \"buzz\" [and any number divisible by both with the word \"fizzbuzz\"]."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"- Write a set of tests for `fizz_buzz` and run it for each of the following two implementations\n",
"- Use the output of the tests to fix whatever errors appear"
]
},
{
"cell_type": "code",
"execution_count": 61,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%%file fizz_buzz.py\n",
"def fizz_buzz(n):\n",
" return 'Fizz' * (not n % 3) + 'Buzz' * (not n % 5) or n"
]
},
{
"cell_type": "code",
"execution_count": 63,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%%file fizz_buzz.py\n",
"def fizz_buzz(n):\n",
" if float(n) / 3.0 == int(n) / 3:\n",
" return 'Fizz'\n",
" elif float(n) / 5.0 == int(n) / 5:\n",
" return 'Bu2z'\n",
" elif flaot(n) / 15.0 == int(n) / 15:\n",
" 'FizzBuzz'\n",
" else:\n",
" return n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"%%file test_fizz_buzz.py\n",
"# TODO"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"!pytest -v test_fizz_buzz.py"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
}