Programming Interviews: Fizz Buzz

An all-time programming classic for interviews

Photo by Christina @ wocintechchat.com on Unsplash

Problem Statement

Solution

def fizzbuzz(number: int) -> str:
if number % 15 == 0:
return "Fizz Buzz"
if number % 3 == 0:
return "Fizz"
if number % 5 == 0:
return "Buzz"
return str(number)

Unit Tests

from fizzbuzz import fizzbuzzdef test_3():
assert fizzbuzz(3) == "Fizz"
assert fizzbuzz(6) == "Fizz"
assert fizzbuzz(9) == "Fizz"
assert fizzbuzz(12) == "Fizz"
def test_5():
assert fizzbuzz(5) == "Buzz"
assert fizzbuzz(10) == "Buzz"
assert fizzbuzz(20) == "Buzz"
def test_15():
assert fizzbuzz(15) == "Fizz Buzz"
assert fizzbuzz(30) == "Fizz Buzz"
assert fizzbuzz(45) == "Fizz Buzz"
def test_number():
assert fizzbuzz(1) == "1"
assert fizzbuzz(2) == "2"
def test_edge_cases():
assert fizzbuzz(-1) == "-1"
assert fizzbuzz(3 ** 20) == "Fizz"
assert fizzbuzz(-(3 ** 20)) == "Fizz"
assert fizzbuzz(0) == "Fizz Buzz"

Extensions

Typical Mistakes

What I (don’t) learn as an Interviewer

TL;DR: Score of “Fizz Buzz” for Interviews

What’s next?

I’m a Software Engineer with focus on Security, Data Science, and ML. I have over 10 years of experience with Python. https://www.linkedin.com/in/martin-thoma/

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store