foozbuzz / Week 2 / due: 2018-01-19 23:59

A variation on the “FizzBuzz” exercise, a programming challenge that seems incredibly trivial yet apparently CS grads and PhDs fail at (according to industry recruiters).

Description

What is FizzBuzz

This blog post is more than a decade old, yet Fizzbuzz challenge remains:

Using FizzBuzz to Find Developers who Grok Coding - Imran Ghory

After a fair bit of trial and error I’ve come to discover that people who struggle to code don’t just struggle on big problems, or even smallish problems (i.e. write a implementation of a linked list). They struggle with tiny problems.

So I set out to develop questions that can identify this kind of developer and came up with a class of questions I call “FizzBuzz Questions” named after a game children often play (or are made to play) in schools in the UK.

Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.

More info: Why programmers can’t program

What is foozbuzz

Pretty much the same thing as the FizzBuzz problem, but with a small variation so you get some practice with redesigning/refactoring functions.

This assignment basically requires you to fulfill the original conditions as “FizzBuzz”, which are:

  • Count from 1 to 100
  • For every number divisible by 3, print “Fizz”
  • For every number divisible by 5, print “Buzz”
  • For numbers divisible by both 3 and 5, print “FizzBuzz”
  • For all other numbers, print just the number.

Here are the foozbuzz variations:

  • The foozbuzz program should allow user to pick which number to count to, i.e. something other than 100.
  • Unlike FizzBuzz, foozbuzz always prints the current number, along with “Fizz” or “Buzz” or “FizzBuzz”
  • The foozbuzz program provides a function named fob, which takes one variable (the number to count to).

Assuming all of the code is in a file named fooz.py, this is how someone would use fob to print the values from 1 to 22:

from fooz import fob

fob(22)

Requirements

This section details the exact requirements I expect from your homework folder, including the existence and correct spelling of filenames, to expected behavior when I run your code. You might as well assume that your code is being run by an automated process, a process that will fail upon even a typo.

In places where you see, SUNETID, e.g.

compciv-2018-SUNETID/week-00/foo_bar/

Replace it with your own SUnet ID. For example, if your SUnet ID is dun:

compciv-2018-dun/week-00/foo_bar/

Expected files

Your compciv repo is basically a folder of files, what’s on Github.com is basically the same as what’s on the repo as stored on your own computer. But for the sake of clarity, I explain what things should look like whether I’m visiting your repo on Github.com, or if I’ve cloned your repo onto my own computer.

When I visit your Github.com repo page

I expect your Github repo at compciv-2018-SUNETID repo to have the following subfolder:

compciv-2018-SUNETID/week-02/foozbuzz/

On this subfolder’s page, I would expect the file tree to look like this:

└── fooz.py

When I clone your Github repo

If I were to clone your repo onto my own computer, e.g.

$ git clone https://github.com/GITHUBID/compciv-2018-SUNETID.git

I would expect your homework subfolder to look like this:

compciv-2018-SUNETID/
└── week-02/
    └── foozbuzz/
        └── fooz.py

Expected behavior and results

After I’ve cloned your Github repo, assume that I will run the following shell commands and/or Python scripts, and expect the stated output and effects.

Test A. Using fob() to print values from 1 to 20

I expect to run the following shell command to change into the foozbuzz directory:

$ cd compciv-2018-SUNETID/week-02/foozbuzz/

From this location, I expect to go into something like ipython, and access the fob function, as defined in fooz.py:

>>> from fooz import fob
>>> fob(15)

I expect this exact output to my screen:

1
2
3 Fizz
4
5 Buzz
6 Fizz
7
8
9 Fizz
10 Buzz
11
12 Fizz
13
14
15 FizzBuzz

Walkthrough

You can Google the solution to “FizzBuzz” very easily, that’s not the point of this exercise.

Let’s assume you are new to Python and unfamiliar to programming, and take this as a chance to show the process of breaking things down into mangeable tasks:

  • How do we use Python to print values
  • What is the best way to generate a list of numbers from 1 to 100, or anything?
  • How to tell if number is divisible by 5 or 3, or, both?
  • How to design program that “reacts” differently to each number?
  • How to wrap it up in a function?
  • How to write a function that lets user specify a value to count to?